Skip to content

Commit

Permalink
Improve <style> tag parsing and add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dgreensp committed Mar 27, 2015
1 parent 0ede8a4 commit dcdfea3
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 2 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* Blaze: Improve parsing of `<script>` and `<style>` tags. #3797

## v.NEXT

### Version Solver
Expand Down
2 changes: 1 addition & 1 deletion packages/html-tools/parse.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ getContent = HTMLTools.Parse.getContent = function (scanner, shouldStopFunc) {
attrs.value = textareaValue;
}
}
} else if (token.n === 'script') {
} else if (token.n === 'script' || token.n === 'style') {
content = getRawText(scanner, token.n, shouldStopFunc);
} else {
content = getContent(scanner, shouldStopFunc);
Expand Down
32 changes: 32 additions & 0 deletions packages/html-tools/parse_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var DIV = HTML.DIV;
var P = HTML.P;
var TEXTAREA = HTML.TEXTAREA;
var SCRIPT = HTML.SCRIPT;
var STYLE = HTML.STYLE;

Tinytest.add("html-tools - parser getContent", function (test) {

Expand Down Expand Up @@ -150,8 +151,39 @@ Tinytest.add("html-tools - parser getContent", function (test) {
succeed('<br x="\r\r">', BR({x:'\n\n'}));
succeed('<br x=y\r>', BR({x:'y'}));
fatal('<br x=\r>');

succeed('<script>var x="<div>";</script>',SCRIPT('var x="<div>";'));
succeed('<script>var x=1 && 0;</script>',SCRIPT('var x=1 && 0;'));

succeed('<script>asdf</script>', SCRIPT("asdf"));
succeed('<script x=y>asdf</script>', SCRIPT({x: "y"}, "asdf"));
succeed('<script><p></script>', SCRIPT("<p>"));
succeed('<script>a&amp;b</script>', SCRIPT("a&amp;b"));
succeed('<script></script</script>', SCRIPT("</script"));
succeed('<script>\n</script>', SCRIPT("\n"));
succeed('<script><!-- --></script>', SCRIPT("<!-- -->"));
succeed('<sCrIpT>asdf</SCRipt>', SCRIPT("asdf"));
fatal('<script>asdf');
fatal('<script>asdf</script');
succeed('<script>&davidgreenspan;</script>', SCRIPT("&davidgreenspan;"));
succeed('<script>&</script>', SCRIPT("&"));
succeed('<script></script \n<</script \n>asdf',
[SCRIPT("</script \n<"), "asdf"]);

succeed('<style>asdf</style>', STYLE("asdf"));
succeed('<style x=y>asdf</style>', STYLE({x: "y"}, "asdf"));
succeed('<style><p></style>', STYLE("<p>"));
succeed('<style>a&amp;b</style>', STYLE("a&amp;b"));
succeed('<style></style</style>', STYLE("</style"));
succeed('<style>\n</style>', STYLE("\n"));
succeed('<style><!-- --></style>', STYLE("<!-- -->"));
succeed('<sTyLe>asdf</STYle>', STYLE("asdf"));
fatal('<style>asdf');
fatal('<style>asdf</style');
succeed('<style>&davidgreenspan;</style>', STYLE("&davidgreenspan;"));
succeed('<style>&</style>', STYLE("&"));
succeed('<style></style \n<</style \n>asdf',
[STYLE("</style \n<"), "asdf"]);
});

Tinytest.add("html-tools - parseFragment", function (test) {
Expand Down

0 comments on commit dcdfea3

Please sign in to comment.