Sat, 03 Jan 2015 20:18:00 +0100
Conditionally enable double key logic according to:
private browsing mode or privacy.thirdparty.isolate preference and
implement in GetCookieStringCommon and FindCookie where it counts...
With some reservations of how to convince FindCookie users to test
condition and pass a nullptr when disabling double key logic.
michael@0 | 1 | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
michael@0 | 2 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 5 | |
michael@0 | 6 | /* |
michael@0 | 7 | * |
michael@0 | 8 | * Date: 23 October 2003 |
michael@0 | 9 | * SUMMARY: Unescaped, unbalanced parens in a regexp should cause SyntaxError. |
michael@0 | 10 | * |
michael@0 | 11 | * The same would also be true for unescaped, unbalanced brackets or braces |
michael@0 | 12 | * if we followed the ECMA-262 Ed. 3 spec on this. But it was decided for |
michael@0 | 13 | * backward compatibility reasons to follow Perl 5, which permits |
michael@0 | 14 | * |
michael@0 | 15 | * 1. an unescaped, unbalanced right bracket ] |
michael@0 | 16 | * 2. an unescaped, unbalanced left brace { |
michael@0 | 17 | * 3. an unescaped, unbalanced right brace } |
michael@0 | 18 | * |
michael@0 | 19 | * If any of these should occur, Perl treats each as a literal |
michael@0 | 20 | * character. Therefore we permit all three of these cases, even |
michael@0 | 21 | * though not ECMA-compliant. Note Perl errors on an unescaped, |
michael@0 | 22 | * unbalanced left bracket; so will we. |
michael@0 | 23 | * |
michael@0 | 24 | * See http://bugzilla.mozilla.org/show_bug.cgi?id=223273 |
michael@0 | 25 | * |
michael@0 | 26 | */ |
michael@0 | 27 | //----------------------------------------------------------------------------- |
michael@0 | 28 | var UBound = 0; |
michael@0 | 29 | var BUGNUMBER = 223273; |
michael@0 | 30 | var summary = 'Unescaped, unbalanced parens in regexp should be a SyntaxError'; |
michael@0 | 31 | var TEST_PASSED = 'SyntaxError'; |
michael@0 | 32 | var TEST_FAILED = 'Generated an error, but NOT a SyntaxError!'; |
michael@0 | 33 | var TEST_FAILED_BADLY = 'Did not generate ANY error!!!'; |
michael@0 | 34 | var CHECK_PASSED = 'Should not generate an error'; |
michael@0 | 35 | var CHECK_FAILED = 'Generated an error!'; |
michael@0 | 36 | var status = ''; |
michael@0 | 37 | var statusitems = []; |
michael@0 | 38 | var actual = ''; |
michael@0 | 39 | var actualvalues = []; |
michael@0 | 40 | var expect= ''; |
michael@0 | 41 | var expectedvalues = []; |
michael@0 | 42 | |
michael@0 | 43 | |
michael@0 | 44 | /* |
michael@0 | 45 | * All the following contain unescaped, unbalanced parens and |
michael@0 | 46 | * should generate SyntaxErrors. That's what we're testing for. |
michael@0 | 47 | * |
michael@0 | 48 | * To allow the test to compile and run, we have to hide the errors |
michael@0 | 49 | * inside eval strings, and check they are caught at run-time. |
michael@0 | 50 | * |
michael@0 | 51 | * Inside such strings, remember to escape any escape character! |
michael@0 | 52 | */ |
michael@0 | 53 | status = inSection(1); |
michael@0 | 54 | testThis(' /(/ '); |
michael@0 | 55 | |
michael@0 | 56 | status = inSection(2); |
michael@0 | 57 | testThis(' /)/ '); |
michael@0 | 58 | |
michael@0 | 59 | status = inSection(3); |
michael@0 | 60 | testThis(' /(abc\\)def(g/ '); |
michael@0 | 61 | |
michael@0 | 62 | status = inSection(4); |
michael@0 | 63 | testThis(' /\\(abc)def)g/ '); |
michael@0 | 64 | |
michael@0 | 65 | |
michael@0 | 66 | /* |
michael@0 | 67 | * These regexp patterns are correct and should not generate |
michael@0 | 68 | * any errors. Note we use checkThis() instead of testThis(). |
michael@0 | 69 | */ |
michael@0 | 70 | status = inSection(5); |
michael@0 | 71 | checkThis(' /\\(/ '); |
michael@0 | 72 | |
michael@0 | 73 | status = inSection(6); |
michael@0 | 74 | checkThis(' /\\)/ '); |
michael@0 | 75 | |
michael@0 | 76 | status = inSection(7); |
michael@0 | 77 | checkThis(' /(abc)def\\(g/ '); |
michael@0 | 78 | |
michael@0 | 79 | status = inSection(8); |
michael@0 | 80 | checkThis(' /(abc\\)def)g/ '); |
michael@0 | 81 | |
michael@0 | 82 | status = inSection(9); |
michael@0 | 83 | checkThis(' /(abc(\\))def)g/ '); |
michael@0 | 84 | |
michael@0 | 85 | status = inSection(10); |
michael@0 | 86 | checkThis(' /(abc([x\\)yz]+)def)g/ '); |
michael@0 | 87 | |
michael@0 | 88 | |
michael@0 | 89 | |
michael@0 | 90 | /* |
michael@0 | 91 | * Unescaped, unbalanced left brackets should be a SyntaxError |
michael@0 | 92 | */ |
michael@0 | 93 | status = inSection(11); |
michael@0 | 94 | testThis(' /[/ '); |
michael@0 | 95 | |
michael@0 | 96 | status = inSection(12); |
michael@0 | 97 | testThis(' /[abc\\]def[g/ '); |
michael@0 | 98 | |
michael@0 | 99 | |
michael@0 | 100 | /* |
michael@0 | 101 | * We permit unescaped, unbalanced right brackets, as does Perl. |
michael@0 | 102 | * No error should result, even though this is not ECMA-compliant. |
michael@0 | 103 | * Note we use checkThis() instead of testThis(). |
michael@0 | 104 | */ |
michael@0 | 105 | status = inSection(13); |
michael@0 | 106 | checkThis(' /]/ '); |
michael@0 | 107 | |
michael@0 | 108 | status = inSection(14); |
michael@0 | 109 | checkThis(' /\\[abc]def]g/ '); |
michael@0 | 110 | |
michael@0 | 111 | |
michael@0 | 112 | /* |
michael@0 | 113 | * These regexp patterns are correct and should not generate |
michael@0 | 114 | * any errors. Note we use checkThis() instead of testThis(). |
michael@0 | 115 | */ |
michael@0 | 116 | status = inSection(15); |
michael@0 | 117 | checkThis(' /\\[/ '); |
michael@0 | 118 | |
michael@0 | 119 | status = inSection(16); |
michael@0 | 120 | checkThis(' /\\]/ '); |
michael@0 | 121 | |
michael@0 | 122 | status = inSection(17); |
michael@0 | 123 | checkThis(' /[abc]def\\[g/ '); |
michael@0 | 124 | |
michael@0 | 125 | status = inSection(18); |
michael@0 | 126 | checkThis(' /[abc\\]def]g/ '); |
michael@0 | 127 | |
michael@0 | 128 | status = inSection(19); |
michael@0 | 129 | checkThis(' /(abc[\\]]def)g/ '); |
michael@0 | 130 | |
michael@0 | 131 | status = inSection(20); |
michael@0 | 132 | checkThis(' /[abc(x\\]yz+)def]g/ '); |
michael@0 | 133 | |
michael@0 | 134 | |
michael@0 | 135 | |
michael@0 | 136 | /* |
michael@0 | 137 | * Run some tests for unbalanced braces. We again follow Perl, and |
michael@0 | 138 | * thus permit unescaped unbalanced braces - both left and right, |
michael@0 | 139 | * even though this is not ECMA-compliant. |
michael@0 | 140 | * |
michael@0 | 141 | * Note we use checkThis() instead of testThis(). |
michael@0 | 142 | */ |
michael@0 | 143 | status = inSection(21); |
michael@0 | 144 | checkThis(' /abc{def/ '); |
michael@0 | 145 | |
michael@0 | 146 | status = inSection(22); |
michael@0 | 147 | checkThis(' /abc}def/ '); |
michael@0 | 148 | |
michael@0 | 149 | status = inSection(23); |
michael@0 | 150 | checkThis(' /a{2}bc{def/ '); |
michael@0 | 151 | |
michael@0 | 152 | status = inSection(24); |
michael@0 | 153 | checkThis(' /a}b{3}c}def/ '); |
michael@0 | 154 | |
michael@0 | 155 | |
michael@0 | 156 | /* |
michael@0 | 157 | * These regexp patterns are correct and should not generate |
michael@0 | 158 | * any errors. Note we use checkThis() instead of testThis(). |
michael@0 | 159 | */ |
michael@0 | 160 | status = inSection(25); |
michael@0 | 161 | checkThis(' /abc\\{def/ '); |
michael@0 | 162 | |
michael@0 | 163 | status = inSection(26); |
michael@0 | 164 | checkThis(' /abc\\}def/ '); |
michael@0 | 165 | |
michael@0 | 166 | status = inSection(27); |
michael@0 | 167 | checkThis(' /a{2}bc\\{def/ '); |
michael@0 | 168 | |
michael@0 | 169 | status = inSection(28); |
michael@0 | 170 | checkThis(' /a\\}b{3}c\\}def/ '); |
michael@0 | 171 | |
michael@0 | 172 | |
michael@0 | 173 | |
michael@0 | 174 | |
michael@0 | 175 | //----------------------------------------------------------------------------- |
michael@0 | 176 | test(); |
michael@0 | 177 | //----------------------------------------------------------------------------- |
michael@0 | 178 | |
michael@0 | 179 | |
michael@0 | 180 | |
michael@0 | 181 | |
michael@0 | 182 | /* |
michael@0 | 183 | * Invalid syntax should generate a SyntaxError |
michael@0 | 184 | */ |
michael@0 | 185 | function testThis(sInvalidSyntax) |
michael@0 | 186 | { |
michael@0 | 187 | expect = TEST_PASSED; |
michael@0 | 188 | actual = TEST_FAILED_BADLY; |
michael@0 | 189 | |
michael@0 | 190 | try |
michael@0 | 191 | { |
michael@0 | 192 | eval(sInvalidSyntax); |
michael@0 | 193 | } |
michael@0 | 194 | catch(e) |
michael@0 | 195 | { |
michael@0 | 196 | if (e instanceof SyntaxError) |
michael@0 | 197 | actual = TEST_PASSED; |
michael@0 | 198 | else |
michael@0 | 199 | actual = TEST_FAILED; |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | statusitems[UBound] = status; |
michael@0 | 203 | expectedvalues[UBound] = expect; |
michael@0 | 204 | actualvalues[UBound] = actual; |
michael@0 | 205 | UBound++; |
michael@0 | 206 | } |
michael@0 | 207 | |
michael@0 | 208 | |
michael@0 | 209 | /* |
michael@0 | 210 | * Valid syntax shouldn't generate any errors |
michael@0 | 211 | */ |
michael@0 | 212 | function checkThis(sValidSyntax) |
michael@0 | 213 | { |
michael@0 | 214 | expect = CHECK_PASSED; |
michael@0 | 215 | actual = CHECK_PASSED; |
michael@0 | 216 | |
michael@0 | 217 | try |
michael@0 | 218 | { |
michael@0 | 219 | eval(sValidSyntax); |
michael@0 | 220 | } |
michael@0 | 221 | catch(e) |
michael@0 | 222 | { |
michael@0 | 223 | actual = CHECK_FAILED; |
michael@0 | 224 | } |
michael@0 | 225 | |
michael@0 | 226 | statusitems[UBound] = status; |
michael@0 | 227 | expectedvalues[UBound] = expect; |
michael@0 | 228 | actualvalues[UBound] = actual; |
michael@0 | 229 | UBound++; |
michael@0 | 230 | } |
michael@0 | 231 | |
michael@0 | 232 | |
michael@0 | 233 | function test() |
michael@0 | 234 | { |
michael@0 | 235 | enterFunc('test'); |
michael@0 | 236 | printBugNumber(BUGNUMBER); |
michael@0 | 237 | printStatus(summary); |
michael@0 | 238 | |
michael@0 | 239 | for (var i=0; i<UBound; i++) |
michael@0 | 240 | { |
michael@0 | 241 | reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
michael@0 | 242 | } |
michael@0 | 243 | |
michael@0 | 244 | exitFunc ('test'); |
michael@0 | 245 | } |