tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

ParentNode-querySelector-escapes.html (4849B)


      1 <!DOCTYPE html>
      2 <meta charset=utf-8>
      3 <title>querySelector() with CSS escapes</title>
      4 <link rel="help" href="https://dom.spec.whatwg.org/#dom-parentnode-queryselector">
      5 <link rel="help" href="https://drafts.csswg.org/css-syntax/#consume-escaped-code-point">
      6 <link rel="author" title="Domenic Denicola" href="mailto:d@domenic.me">
      7 <link rel="author" title="bellbind" href="mailto:bellbind@gmail.com">
      8 <script src="/resources/testharness.js"></script>
      9 <script src="/resources/testharnessreport.js"></script>
     10 
     11 <script>
     12 "use strict";
     13 
     14 function testMatched(id, selector) {
     15  test(() => {
     16    const container = document.createElement("div");
     17    const child = document.createElement("span");
     18    child.id = id;
     19 
     20    container.appendChild(child);
     21 
     22    assert_equals(container.querySelector(selector), child);
     23  }, `${JSON.stringify(id)} should match with ${JSON.stringify(selector)}`);
     24 }
     25 
     26 function testNeverMatched(id, selector) {
     27  test(() => {
     28    const container = document.createElement("div");
     29    const child = document.createElement("span");
     30    child.id = id;
     31 
     32    container.appendChild(child);
     33 
     34    assert_equals(container.querySelector(selector), null);
     35  }, `${JSON.stringify(id)} should never match with ${JSON.stringify(selector)}`);
     36 }
     37 
     38 // 4.3.7 from https://drafts.csswg.org/css-syntax/#consume-escaped-code-point
     39 testMatched("nonescaped", "#nonescaped");
     40 
     41 // - escape hex digit
     42 testMatched("0nextIsWhiteSpace", "#\\30 nextIsWhiteSpace");
     43 testMatched("0nextIsNotHexLetters", "#\\30nextIsNotHexLetters");
     44 testMatched("0connectHexMoreThan6Hex", "#\\000030connectHexMoreThan6Hex");
     45 testMatched("0spaceMoreThan6Hex", "#\\000030 spaceMoreThan6Hex");
     46 
     47 // - hex digit special replacement
     48 // 1. zero points
     49 testMatched("zero\u{fffd}", "#zero\\0");
     50 testNeverMatched("zero\u{0}", "#zero\\0");
     51 testMatched("zero\u{fffd}", "#zero\\000000");
     52 testNeverMatched("zero\u{0}", "#zero\\000000");
     53 // 2. surrogate points
     54 testMatched("\u{fffd}surrogateFirst", "#\\d83d surrogateFirst");
     55 testNeverMatched("\ud83dsurrogateFirst", "#\\d83d surrogateFirst");
     56 testMatched("surrogateSecond\u{fffd}", "#surrogateSecond\\dd11");
     57 testNeverMatched("surrogateSecond\udd11", "#surrogateSecond\\dd11");
     58 testMatched("surrogatePair\u{fffd}\u{fffd}", "#surrogatePair\\d83d\\dd11");
     59 testNeverMatched("surrogatePair\u{1f511}", "#surrogatePair\\d83d\\dd11");
     60 // 3. out of range points
     61 testMatched("outOfRange\u{fffd}", "#outOfRange\\110000");
     62 testMatched("outOfRange\u{fffd}", "#outOfRange\\110030");
     63 testNeverMatched("outOfRange\u{30}", "#outOfRange\\110030");
     64 testMatched("outOfRange\u{fffd}", "#outOfRange\\555555");
     65 testMatched("outOfRange\u{fffd}", "#outOfRange\\ffffff");
     66 
     67 // - escape EOF
     68 testNeverMatched("eof\\", "#eof\\");
     69 
     70 // - escape anythong else
     71 testMatched(".comma", "#\\.comma");
     72 testMatched("-minus", "#\\-minus");
     73 testMatched("g", "#\\g");
     74 
     75 // non edge cases
     76 testMatched("aBMPRegular", "#\\61 BMPRegular");
     77 testMatched("\u{1f511}nonBMP", "#\\1f511 nonBMP");
     78 testMatched("00continueEscapes", "#\\30\\30 continueEscapes");
     79 testMatched("00continueEscapes", "#\\30 \\30 continueEscapes");
     80 testMatched("continueEscapes00", "#continueEscapes\\30 \\30 ");
     81 testMatched("continueEscapes00", "#continueEscapes\\30 \\30");
     82 testMatched("continueEscapes00", "#continueEscapes\\30\\30 ");
     83 testMatched("continueEscapes00", "#continueEscapes\\30\\30");
     84 
     85 // ident tests case from CSS tests of chromium source: https://goo.gl/3Cxdov
     86 testMatched("hello", "#hel\\6Co");
     87 testMatched("&B", "#\\26 B");
     88 testMatched("hello", "#hel\\6C o");
     89 testMatched("spaces", "#spac\\65\r\ns");
     90 testMatched("spaces", "#sp\\61\tc\\65\fs");
     91 testMatched("test\u{D799}", "#test\\D799");
     92 testMatched("\u{E000}", "#\\E000");
     93 testMatched("test", "#te\\s\\t");
     94 testMatched("spaces in\tident", "#spaces\\ in\\\tident");
     95 testMatched(".,:!", "#\\.\\,\\:\\!");
     96 testMatched("null\u{fffd}", "#null\\0");
     97 testMatched("null\u{fffd}", "#null\\0000");
     98 testMatched("large\u{fffd}", "#large\\110000");
     99 testMatched("large\u{fffd}", "#large\\23456a");
    100 testMatched("surrogate\u{fffd}", "#surrogate\\D800");
    101 testMatched("surrogate\u{fffd}", "#surrogate\\0DBAC");
    102 testMatched("\u{fffd}surrogate", "#\\00DFFFsurrogate");
    103 testMatched("\u{10ffff}", "#\\10fFfF");
    104 testMatched("\u{10ffff}0", "#\\10fFfF0");
    105 testMatched("\u{100000}00", "#\\10000000");
    106 testMatched("eof\u{fffd}", "#eof\\");
    107 
    108 testMatched("simple-ident", "#simple-ident");
    109 testMatched("testing123", "#testing123");
    110 testMatched("_underscore", "#_underscore");
    111 testMatched("-text", "#-text");
    112 testMatched("-m", "#-\\6d");
    113 testMatched("--abc", "#--abc");
    114 testMatched("--", "#--");
    115 testMatched("--11", "#--11");
    116 testMatched("---", "#---");
    117 testMatched("\u{2003}", "#\u{2003}");
    118 testMatched("\u{A0}", "#\u{A0}");
    119 testMatched("\u{1234}", "#\u{1234}");
    120 testMatched("\u{12345}", "#\u{12345}");
    121 testMatched("\u{fffd}", "#\u{0}");
    122 testMatched("ab\u{fffd}c", "#ab\u{0}c");
    123 </script>