Skip to content

Commit

Permalink
Replace unpaired surrogates in result of javascript URLs
Browse files Browse the repository at this point in the history
Given a URL like javascript:String.fromCodePoint(0xDE0D), Chrome
currently displays three U+FFFD replacement characters rather than just
one, due to the incorrect UTF-8 conversion mode. We fix that by using
kStrictUTF8ConversionReplacingUnpairedSurrogatesWithFFFD.

This CL fully implements whatwg/html#6781.
Tests are partially taken from #29419.

Co-authored-by: Domenic Denicola <domenic@chromium.org>
Bug: 1221018
Change-Id: Ic1282d0a88eabb40b4d5d8d8c68e040e9a0a938d
  • Loading branch information
2 people authored and chromium-wpt-export-bot committed Jun 17, 2021
1 parent ec5c1fc commit ae1f6e6
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 51 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<!doctype html>
<meta charset=windows-1252> <!-- intentionally not UTF-8 to test that the javascript: frames are forced to UTF-8 -->
<title>Test javascript URL string return values in direct and indirect (target) frame contexts.</title>
<!-- Waiting on https://github.com/whatwg/html/pull/6781 to be non-tentative. -->
<script src=/resources/testharness.js></script>
<script src=/resources/testharnessreport.js></script>
<div id=log></div>
<script>
const testCases = [
[[0x41]],
[[0x80,0xFF]],
[[0x80,0xFF,0x100]],
[[0xD83D,0xDE0D]],
[[0xDE0D,0x41], [0xFFFD,0x41]]
];

function formatCharCodes(charCodes) {
return charCodes.map(code => code.toString(16).toUpperCase().padStart(4, '0')).join(" ");
}

for (const [input, expected = input] of testCases) {
const javascriptURL = `javascript:String.fromCharCode(${input})`;
const output = String.fromCharCode(...expected);

async_test(t => {
const frame = document.createElement("iframe");
t.add_cleanup(() => frame.remove());
frame.src = javascriptURL;

t.step_timeout(() => {
assert_equals(frame.contentDocument.body.textContent, output);
assert_equals(frame.contentDocument.charset, "UTF-8");
t.done();
}, 200);

document.body.appendChild(frame);
}, `${formatCharCodes(input)} set in src=""`);

async_test(t => {
const frame = document.createElement("iframe");
const href = document.createElement("a");
t.add_cleanup(() => { frame.remove(); href.remove(); });
frame.name = "hi" + input;
href.target = "hi" + input;
href.href = javascriptURL;

t.step_timeout(() => {
assert_equals(frame.contentDocument.body.textContent, output);
assert_equals(frame.contentDocument.charset, "UTF-8");
t.done();
}, 200)

document.body.appendChild(frame);
document.body.appendChild(href);
href.click();
}, `${formatCharCodes(input)} set in href="" targeting a frame and clicked`);
}
</script>

0 comments on commit ae1f6e6

Please sign in to comment.