Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

made slowparse take note of HTML in CSS context, throwing a new HTML_…

…CODE_IN_CSS_BLOCK error
  • Loading branch information...
commit e0a7fe1410bcf85a227984f2905a1ef5839e0c0b 1 parent f3a0d8e
@Pomax Pomax authored
View
18 slowparse.js
@@ -299,6 +299,14 @@ var Slowparse = (function() {
return {
start: start
};
+ },
+ HTML_CODE_IN_CSS_BLOCK: function(parser, start, end) {
+ return {
+ html: {
+ start: start,
+ end: end
+ }
+ }
}
};
@@ -320,6 +328,11 @@ var Slowparse = (function() {
peek: function() {
return this.text[this.pos];
},
+ // `Stream.substream(len)` returns a substream from the stream
+ // without advancing it, with length `len`.
+ substream: function(len) {
+ return this.text.substring(this.pos, this.pos + len);
+ },
// `Stream.next()` returns the next character in the stream and advances
// it. It also returns `undefined` when no more characters are available.
next: function() {
@@ -620,6 +633,11 @@ var Slowparse = (function() {
// or an error occurred.
if (token === null) {
if (!this.stream.end() && this.stream.peek() === '<') {
+ // if this is the start of <!-- make sure to throw an error
+ if (this.stream.substream(2) !== "</") {
+ throw new ParseError("HTML_CODE_IN_CSS_BLOCK", this, this.stream.pos-1,
+ this.stream.pos);
+ }
return;
}
throw new ParseError("MISSING_CSS_SELECTOR", this, this.stream.pos-1,
View
3  spec/errors.base.html
@@ -127,3 +127,6 @@
<p>The CSS comment <em data-highlight="{{start}}">here</em>
doesn't end with a <code>*/</code>.</p>
</div>
+<div class="error-msg HTML_CODE_IN_CSS_BLOCK">
+ <p>HTML code was detected in CSS context starting <em data-highlight="{{html.start}},{{html.end}}">here</em>
+</div>
View
34 spec/index.html
@@ -504,6 +504,40 @@ <h1 class="error-category">CSS Errors</h1>
}
</script>
</div>
+
+<div class="test">
+ <script type="text/x-bad-html">
+ <style>
+ <!-- html comment in CSS block -->
+ </style>
+ </script>
+ <script type="application/json">
+ {
+ "type": "HTML_CODE_IN_CSS_BLOCK",
+ "html": {
+ "start": 13,
+ "end": 14
+ }
+ }
+ </script>
+</div>
+<div class="test">
+ <script type="text/x-bad-html">
+ <style>
+ <p>html code in CSS block</p>
+ </style>
+ </script>
+ <script type="application/json">
+ {
+ "type": "HTML_CODE_IN_CSS_BLOCK",
+ "html": {
+ "start": 13,
+ "end": 14
+ }
+ }
+ </script>
+</div>
+
<div class="test">
<script type="text/x-bad-html">
<style> /* unterminated comment
View
1  test/test-slowparse.js
@@ -325,7 +325,6 @@ testStyleSheet("parsing of CSS rule w/ vendor prefixes",
});
});
-
test("replaceEntityRefs", function() {
[
["&lt;", "<"],
Please sign in to comment.
Something went wrong with that request. Please try again.