-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix <style> and <script> parsing to wait for their close tag
This replaces our previous hacky <script>-only close tag detection, which only worked in non-empty <script> cases, with a more general hacky version that works for all elements, including empty elements, by monkeypatching parse5. (Eventually inikulin/parse5#237 should give us a better solution, but for now we lock our parse5 version and monkeypatch it.) In particular, this allows us to not parse stylesheets before their close tag is encountered, which fixes #2123 and fixes #2131.
- Loading branch information
Showing
9 changed files
with
131 additions
and
52 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
"use strict"; | ||
const { assert } = require("chai"); | ||
const { describe, it } = require("mocha-sugar-free"); | ||
|
||
const { JSDOM, VirtualConsole } = require("../.."); | ||
|
||
describe("API: virtual console jsdomErrors", () => { | ||
// Note that web-platform-tests do not log CSS parsing errors, so this has to be an API test. | ||
it("should not omit invalid stylesheet errors due to spaces (GH-2123)", () => { | ||
const virtualConsole = new VirtualConsole(); | ||
|
||
const errors = []; | ||
virtualConsole.on("jsdomError", e => { | ||
errors.push(e); | ||
}); | ||
|
||
// eslint-disable-next-line no-new | ||
new JSDOM(` | ||
<html> | ||
<head></head> | ||
<body> | ||
<style> | ||
.cool-class { | ||
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | ||
} | ||
</style> | ||
<p class="cool-class"> | ||
Hello! | ||
</p> | ||
</body> | ||
</html> | ||
`, { virtualConsole }); | ||
|
||
assert.isEmpty(errors); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
...ests/to-upstream/html/semantics/document-metadata/the-style-element/non-parser-style.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Non-parser-inserted style elements should still work</title> | ||
<link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me"> | ||
<link rel="help" href="https://html.spec.whatwg.org/multipage/semantics.html#update-a-style-block"> | ||
<link rel="help" href="https://drafts.csswg.org/cssom/#the-linkstyle-interface"> | ||
|
||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<p>Test</p> | ||
|
||
<script> | ||
"use strict"; | ||
|
||
const el = document.createElement("style"); | ||
el.textContent = "p { color: rgb(1, 2, 3); }"; | ||
document.head.appendChild(el); | ||
|
||
assert_not_equals(el.sheet, null); | ||
assert_true(el.sheet instanceof CSSStyleSheet); | ||
assert_array_equals(document.styleSheets, [el.sheet]); | ||
|
||
assert_equals(getComputedStyle(document.querySelector("p")).color, "rgb(1, 2, 3)"); | ||
|
||
done(); | ||
</script> |
27 changes: 27 additions & 0 deletions
27
...orm-tests/to-upstream/html/semantics/document-metadata/the-style-element/with-spaces.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<!DOCTYPE html> | ||
<meta charset="utf-8"> | ||
<title>Spaces inside style sheet properties should work fine</title> | ||
<link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me"> | ||
<!-- Regression test for https://github.com/tmpvar/jsdom/issues/2123 --> | ||
|
||
<style> | ||
.cool-class { | ||
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; | ||
} | ||
</style> | ||
|
||
<script src="/resources/testharness.js"></script> | ||
<script src="/resources/testharnessreport.js"></script> | ||
|
||
<p class="cool-class"> | ||
Hello! | ||
</p> | ||
|
||
<script> | ||
"use strict"; | ||
|
||
const el = document.querySelector(".cool-class"); | ||
assert_equals(window.getComputedStyle(el).fontFamily, `"Helvetica Neue", Helvetica, Arial, sans-serif`); | ||
|
||
done(); | ||
</script> |