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: 21 January 2003 |
michael@0 | 9 | * SUMMARY: Invalid use of regexp quantifiers should generate SyntaxErrors |
michael@0 | 10 | * |
michael@0 | 11 | * See http://bugzilla.mozilla.org/show_bug.cgi?id=188206 |
michael@0 | 12 | * and http://bugzilla.mozilla.org/show_bug.cgi?id=85721#c48 etc. |
michael@0 | 13 | * and http://bugzilla.mozilla.org/show_bug.cgi?id=190685 |
michael@0 | 14 | * and http://bugzilla.mozilla.org/show_bug.cgi?id=197451 |
michael@0 | 15 | */ |
michael@0 | 16 | //----------------------------------------------------------------------------- |
michael@0 | 17 | var UBound = 0; |
michael@0 | 18 | var BUGNUMBER = 188206; |
michael@0 | 19 | var summary = 'Invalid use of regexp quantifiers should generate SyntaxErrors'; |
michael@0 | 20 | var TEST_PASSED = 'SyntaxError'; |
michael@0 | 21 | var TEST_FAILED = 'Generated an error, but NOT a SyntaxError!'; |
michael@0 | 22 | var TEST_FAILED_BADLY = 'Did not generate ANY error!!!'; |
michael@0 | 23 | var CHECK_PASSED = 'Should not generate an error'; |
michael@0 | 24 | var CHECK_FAILED = 'Generated an error!'; |
michael@0 | 25 | var status = ''; |
michael@0 | 26 | var statusitems = []; |
michael@0 | 27 | var actual = ''; |
michael@0 | 28 | var actualvalues = []; |
michael@0 | 29 | var expect= ''; |
michael@0 | 30 | var expectedvalues = []; |
michael@0 | 31 | |
michael@0 | 32 | |
michael@0 | 33 | /* |
michael@0 | 34 | * All the following are invalid uses of regexp quantifiers and |
michael@0 | 35 | * should generate SyntaxErrors. That's what we're testing for. |
michael@0 | 36 | * |
michael@0 | 37 | * To allow the test to compile and run, we have to hide the errors |
michael@0 | 38 | * inside eval strings, and check they are caught at run-time - |
michael@0 | 39 | * |
michael@0 | 40 | */ |
michael@0 | 41 | status = inSection(1); |
michael@0 | 42 | testThis(' /a**/ '); |
michael@0 | 43 | |
michael@0 | 44 | status = inSection(2); |
michael@0 | 45 | testThis(' /a***/ '); |
michael@0 | 46 | |
michael@0 | 47 | status = inSection(3); |
michael@0 | 48 | testThis(' /a++/ '); |
michael@0 | 49 | |
michael@0 | 50 | status = inSection(4); |
michael@0 | 51 | testThis(' /a+++/ '); |
michael@0 | 52 | |
michael@0 | 53 | /* |
michael@0 | 54 | * The ? quantifier, unlike * or +, may appear twice in succession. |
michael@0 | 55 | * Thus we need at least three in a row to provoke a SyntaxError - |
michael@0 | 56 | */ |
michael@0 | 57 | |
michael@0 | 58 | status = inSection(5); |
michael@0 | 59 | testThis(' /a???/ '); |
michael@0 | 60 | |
michael@0 | 61 | status = inSection(6); |
michael@0 | 62 | testThis(' /a????/ '); |
michael@0 | 63 | |
michael@0 | 64 | |
michael@0 | 65 | /* |
michael@0 | 66 | * Now do some weird things on the left side of the regexps - |
michael@0 | 67 | */ |
michael@0 | 68 | status = inSection(9); |
michael@0 | 69 | testThis(' /+a/ '); |
michael@0 | 70 | |
michael@0 | 71 | status = inSection(10); |
michael@0 | 72 | testThis(' /++a/ '); |
michael@0 | 73 | |
michael@0 | 74 | status = inSection(11); |
michael@0 | 75 | testThis(' /?a/ '); |
michael@0 | 76 | |
michael@0 | 77 | status = inSection(12); |
michael@0 | 78 | testThis(' /??a/ '); |
michael@0 | 79 | |
michael@0 | 80 | |
michael@0 | 81 | /* |
michael@0 | 82 | * Misusing the {DecmalDigits} quantifier - according to BOTH ECMA and Perl. |
michael@0 | 83 | * |
michael@0 | 84 | * Just as with the * and + quantifiers above, can't have two {DecmalDigits} |
michael@0 | 85 | * quantifiers in succession - it's a SyntaxError. |
michael@0 | 86 | */ |
michael@0 | 87 | status = inSection(28); |
michael@0 | 88 | testThis(' /x{1}{1}/ '); |
michael@0 | 89 | |
michael@0 | 90 | status = inSection(29); |
michael@0 | 91 | testThis(' /x{1,}{1}/ '); |
michael@0 | 92 | |
michael@0 | 93 | status = inSection(30); |
michael@0 | 94 | testThis(' /x{1,2}{1}/ '); |
michael@0 | 95 | |
michael@0 | 96 | status = inSection(31); |
michael@0 | 97 | testThis(' /x{1}{1,}/ '); |
michael@0 | 98 | |
michael@0 | 99 | status = inSection(32); |
michael@0 | 100 | testThis(' /x{1,}{1,}/ '); |
michael@0 | 101 | |
michael@0 | 102 | status = inSection(33); |
michael@0 | 103 | testThis(' /x{1,2}{1,}/ '); |
michael@0 | 104 | |
michael@0 | 105 | status = inSection(34); |
michael@0 | 106 | testThis(' /x{1}{1,2}/ '); |
michael@0 | 107 | |
michael@0 | 108 | status = inSection(35); |
michael@0 | 109 | testThis(' /x{1,}{1,2}/ '); |
michael@0 | 110 | |
michael@0 | 111 | status = inSection(36); |
michael@0 | 112 | testThis(' /x{1,2}{1,2}/ '); |
michael@0 | 113 | |
michael@0 | 114 | |
michael@0 | 115 | |
michael@0 | 116 | //----------------------------------------------------------------------------- |
michael@0 | 117 | test(); |
michael@0 | 118 | //----------------------------------------------------------------------------- |
michael@0 | 119 | |
michael@0 | 120 | |
michael@0 | 121 | |
michael@0 | 122 | /* |
michael@0 | 123 | * Invalid syntax should generate a SyntaxError |
michael@0 | 124 | */ |
michael@0 | 125 | function testThis(sInvalidSyntax) |
michael@0 | 126 | { |
michael@0 | 127 | expect = TEST_PASSED; |
michael@0 | 128 | actual = TEST_FAILED_BADLY; |
michael@0 | 129 | |
michael@0 | 130 | try |
michael@0 | 131 | { |
michael@0 | 132 | eval(sInvalidSyntax); |
michael@0 | 133 | } |
michael@0 | 134 | catch(e) |
michael@0 | 135 | { |
michael@0 | 136 | if (e instanceof SyntaxError) |
michael@0 | 137 | actual = TEST_PASSED; |
michael@0 | 138 | else |
michael@0 | 139 | actual = TEST_FAILED; |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | statusitems[UBound] = status; |
michael@0 | 143 | expectedvalues[UBound] = expect; |
michael@0 | 144 | actualvalues[UBound] = actual; |
michael@0 | 145 | UBound++; |
michael@0 | 146 | } |
michael@0 | 147 | |
michael@0 | 148 | |
michael@0 | 149 | /* |
michael@0 | 150 | * Allowed syntax shouldn't generate any errors |
michael@0 | 151 | */ |
michael@0 | 152 | function checkThis(sAllowedSyntax) |
michael@0 | 153 | { |
michael@0 | 154 | expect = CHECK_PASSED; |
michael@0 | 155 | actual = CHECK_PASSED; |
michael@0 | 156 | |
michael@0 | 157 | try |
michael@0 | 158 | { |
michael@0 | 159 | eval(sAllowedSyntax); |
michael@0 | 160 | } |
michael@0 | 161 | catch(e) |
michael@0 | 162 | { |
michael@0 | 163 | actual = CHECK_FAILED; |
michael@0 | 164 | } |
michael@0 | 165 | |
michael@0 | 166 | statusitems[UBound] = status; |
michael@0 | 167 | expectedvalues[UBound] = expect; |
michael@0 | 168 | actualvalues[UBound] = actual; |
michael@0 | 169 | UBound++; |
michael@0 | 170 | } |
michael@0 | 171 | |
michael@0 | 172 | |
michael@0 | 173 | function test() |
michael@0 | 174 | { |
michael@0 | 175 | enterFunc('test'); |
michael@0 | 176 | printBugNumber(BUGNUMBER); |
michael@0 | 177 | printStatus(summary); |
michael@0 | 178 | |
michael@0 | 179 | for (var i=0; i<UBound; i++) |
michael@0 | 180 | { |
michael@0 | 181 | reportCompare(expectedvalues[i], actualvalues[i], statusitems[i]); |
michael@0 | 182 | } |
michael@0 | 183 | |
michael@0 | 184 | exitFunc ('test'); |
michael@0 | 185 | } |