test_parse_url.html (6980B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=473914 5 --> 6 <head> 7 <title>Test for Bug 473914</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=473914">Mozilla Bug 473914</a> 13 <p id="display"></p> 14 <div id="content" style="display: none"> 15 16 </div> 17 <pre id="test"> 18 <script type="application/javascript"> 19 20 /** Test for Bug 473914 */ 21 22 var div = document.getElementById("content"); 23 24 // This test relies on normalization (insertion of quote marks) that 25 // we're not really guaranteed to continue doing in the future. 26 div.style.listStyleImage = 'url(http://example.org/**/)'; 27 is(div.style.listStyleImage, 'url("http://example.org/**/")', 28 "not treated as comment"); 29 div.style.listStyleImage = 'url("http://example.org/**/")'; 30 is(div.style.listStyleImage, 'url("http://example.org/**/")', 31 "not treated as comment"); 32 div.style.listStyleImage = 'url(/**/foo)'; 33 is(div.style.listStyleImage, 'url("/**/foo")', 34 "not treated as comment"); 35 div.style.listStyleImage = 'url("/**/foo")'; 36 is(div.style.listStyleImage, 'url("/**/foo")', 37 "not treated as comment"); 38 div.style.listStyleImage = 'url(/**/)'; 39 is(div.style.listStyleImage, 'url("/**/")', 40 "not treated as comment"); 41 div.style.listStyleImage = 'url("/**/")'; 42 is(div.style.listStyleImage, 'url("/**/")', 43 "not treated as comment"); 44 45 // Tests from Alfred Keyser's patch in bug 337287 (modified by dbaron) 46 div.style.listStyleImage = 'url("bad")'; 47 div.style.listStyleImage = 'url(good /*bad comment*/)'; 48 is(div.style.listStyleImage, 'url("bad")', 49 "comment not allowed inside token"); 50 51 div.style.listStyleImage = 'url(good /*bad comments*/ /*Hello*/)'; 52 is(div.style.listStyleImage, 'url("bad")', 53 "comment not allowed inside token"); 54 55 div.style.listStyleImage = 'url(good/*commentaspartofurl*/)'; 56 is(div.style.listStyleImage, 'url("good/*commentaspartofurl*/")', 57 "comment-like syntax not comment inside of url"); 58 59 div.style.listStyleImage = 'url("bad")'; 60 div.style.listStyleImage = 'url(good/**/ /*secondcommentcanbeskipped*/ )'; 61 is(div.style.listStyleImage, 'url("bad")', 62 "comment not allowed inside token"); 63 64 div.style.listStyleImage = 'url(/*partofurl*/good)'; 65 is(div.style.listStyleImage, 'url("/*partofurl*/good")', 66 "comment not parsed as part of url"); 67 68 div.style.listStyleImage = 'url(good'; 69 is(div.style.listStyleImage, 'url("good")', 70 "URL ending with eof not correctly handled"); 71 72 div.style.listStyleImage = 'url("bad")'; 73 div.style.listStyleImage = 'url(good /*)*/'; 74 is(div.style.listStyleImage, 'url("bad")', 75 "comment not allowed inside token"); 76 77 div.style.listStyleImage = 'url("bad")'; 78 div.style.listStyleImage = 'url(good /*)*/ tokenaftercommentevenwithclosebracketisinvalid'; 79 is(div.style.listStyleImage, 'url("bad")', 80 "comment not allowed inside token"); 81 82 div.style.listStyleImage = 'url(bad)'; 83 div.style.listStyleImage = 'url("good"'; 84 is(div.style.listStyleImage, 'url("good")', 85 "URL as string without close bracket"); 86 87 div.style.listStyleImage = 'url(bad)'; 88 div.style.listStyleImage = 'url("good'; 89 is(div.style.listStyleImage, 'url("good")', 90 "URL as string without closing quote"); 91 92 div.style.listStyleImage = 'url("bad")'; 93 div.style.listStyleImage = 'url(good notgood'; 94 is(div.style.listStyleImage, 'url("bad")', 95 "second token should make url invalid"); 96 97 div.style.listStyleImage = 'url("bad")'; 98 div.style.listStyleImage = 'url(good(notgood'; 99 is(div.style.listStyleImage, 'url("bad")', 100 "open bracket in url not recognized as invalid"); 101 102 var longurl = ''; 103 for (i=0;i<1000;i++) { 104 longurl = longurl + 'verylongurlindeed_thequickbrownfoxjumpsoverthelazydoq'; 105 } 106 div.style.listStyleImage = 'url(' + longurl; 107 is(div.style.listStyleImage, 'url("' + longurl + '")', 108 "very long url not correctly parsed"); 109 110 111 // Additional tests from 112 // https://bugzilla.mozilla.org/show_bug.cgi?id=337287#c21 113 114 div.style.listStyleImage = 'url(good/*)'; 115 is(div.style.listStyleImage, 'url("good/*")', 116 "URL containing comment start is valid"); 117 118 div.style.listStyleImage = 'url("bad")'; 119 div.style.listStyleImage = 'url(good bad)'; 120 is(div.style.listStyleImage, 'url("bad")', 121 "unquoted URL with spaces not allowed"); 122 123 div.style.listStyleImage = 'url(\\g b)'; 124 is(div.style.listStyleImage, 'url("bad")', 125 "unquoted URL with spaces not allowed"); 126 127 div.style.listStyleImage = 'url( \\g b)'; 128 is(div.style.listStyleImage, 'url("bad")', 129 "unquoted URL with spaces not allowed"); 130 131 div.style.listStyleImage = 'url(c\\g b)'; 132 is(div.style.listStyleImage, 'url("bad")', 133 "unquoted URL with spaces not allowed"); 134 135 div.style.listStyleImage = 'url(cc\\g b)'; 136 is(div.style.listStyleImage, 'url("bad")', 137 "unquoted URL with spaces not allowed"); 138 139 div.style.listStyleImage = 'url(\\f b)'; 140 is(div.style.listStyleImage, 'url("bad")', 141 "unquoted URL with spaces not allowed"); 142 143 div.style.listStyleImage = 'url( \\f b)'; 144 is(div.style.listStyleImage, 'url("bad")', 145 "unquoted URL with spaces not allowed"); 146 147 div.style.listStyleImage = 'url(c\\f b)'; 148 is(div.style.listStyleImage, 'url("bad")', 149 "unquoted URL with spaces not allowed"); 150 151 div.style.listStyleImage = 'url(cc\\f b)'; 152 is(div.style.listStyleImage, 'url("bad")', 153 "unquoted URL with spaces not allowed"); 154 155 var chars = [ 1, 2, 3, 4, 5, 6, 7, 8, 11, 14, 15, 16, 17, 18, 19, 20, 156 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 127]; 157 158 for (var i in chars) { 159 var charcode = chars[i]; 160 div.style.listStyleImage = 'url(' + String.fromCharCode(charcode) + ')'; 161 is(div.style.listStyleImage, 'url("bad")', 162 "unquoted URL with control character " + charcode + " not allowed"); 163 } 164 165 div.style.listStyleImage = 'url(\u00ff)'; 166 is(div.style.listStyleImage, 'url("\u00ff")', "U+A0-U+FF allowed in unquoted URL"); 167 168 div.style.listStyleImage = 'url(\\f good)'; 169 is(div.style.listStyleImage, 'url("\\f good")', "URL allowed"); 170 div.style.listStyleImage = 'url( \\f good)'; 171 is(div.style.listStyleImage, 'url("\\f good")', "URL allowed"); 172 div.style.listStyleImage = 'url(f\\f good)'; 173 is(div.style.listStyleImage, 'url("f\\f good")', "URL allowed"); 174 div.style.listStyleImage = 'url(go\\od)'; 175 is(div.style.listStyleImage, 'url("good")', "URL allowed"); 176 div.style.listStyleImage = 'url(goo\\d)'; 177 is(div.style.listStyleImage, 'url("goo\\d ")', "URL allowed"); 178 div.style.listStyleImage = 'url(go\\o)'; 179 is(div.style.listStyleImage, 'url("goo")', "URL allowed"); 180 181 div.setAttribute("style", "color: url(/*); color: green"); 182 is(div.style.color, 'green', 183 "URL tokenized correctly outside properties taking URLs"); 184 185 div.style.listStyleImage = 'url("foo\\\nbar1")'; 186 is(div.style.listStyleImage, 'url("foobar1")', 187 "escaped newline allowed in string form of URL"); 188 div.style.listStyleImage = 'url(foo\\\nbar2)'; 189 is(div.style.listStyleImage, 'url("foobar1")', 190 "escaped newline NOT allowed in NON-string form of URL"); 191 192 </script> 193 </pre> 194 </body> 195 </html>