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: 18 Feb 2002 |
michael@0 | 9 | * SUMMARY: Testing re.exec(str) when re.lastIndex is < 0 or > str.length |
michael@0 | 10 | * |
michael@0 | 11 | * Case 1: If re has the global flag set, then re(str) should be null |
michael@0 | 12 | * Case 2: If re doesn't have this set, then re(str) should be unaffected |
michael@0 | 13 | * |
michael@0 | 14 | * See http://bugzilla.mozilla.org/show_bug.cgi?id=76717 |
michael@0 | 15 | * |
michael@0 | 16 | * |
michael@0 | 17 | * From the ECMA-262 Final spec: |
michael@0 | 18 | * |
michael@0 | 19 | * 15.10.6.2 RegExp.prototype.exec(string) |
michael@0 | 20 | * Performs a regular expression match of string against the regular |
michael@0 | 21 | * expression and returns an Array object containing the results of |
michael@0 | 22 | * the match, or null if the string did not match. |
michael@0 | 23 | * |
michael@0 | 24 | * The string ToString(string) is searched for an occurrence of the |
michael@0 | 25 | * regular expression pattern as follows: |
michael@0 | 26 | * |
michael@0 | 27 | * 1. Let S be the value of ToString(string). |
michael@0 | 28 | * 2. Let length be the length of S. |
michael@0 | 29 | * 3. Let lastIndex be the value of the lastIndex property. |
michael@0 | 30 | * 4. Let i be the value of ToInteger(lastIndex). |
michael@0 | 31 | * 5. If the global property is false, let i = 0. |
michael@0 | 32 | * 6. If i < 0 or i > length then set lastIndex to 0 and return null. |
michael@0 | 33 | * 7. Call [[Match]], giving it the arguments S and i. |
michael@0 | 34 | * If [[Match]] returned failure, go to step 8; |
michael@0 | 35 | * otherwise let r be its State result and go to step 10. |
michael@0 | 36 | * 8. Let i = i+1. |
michael@0 | 37 | * 9. Go to step 6. |
michael@0 | 38 | * 10. Let e be r's endIndex value. |
michael@0 | 39 | * 11. If the global property is true, set lastIndex to e. |
michael@0 | 40 | * |
michael@0 | 41 | * etc. |
michael@0 | 42 | * |
michael@0 | 43 | * |
michael@0 | 44 | * So: |
michael@0 | 45 | * |
michael@0 | 46 | * A. If the global flag is not set, |lastIndex| is set to 0 |
michael@0 | 47 | * before the match is attempted; thus the match is unaffected. |
michael@0 | 48 | * |
michael@0 | 49 | * B. If the global flag IS set and re.lastIndex is >= 0 and <= str.length, |
michael@0 | 50 | * |lastIndex| is incremented every time there is a match; not from |
michael@0 | 51 | * i to i+1, but from i to "endIndex" e: |
michael@0 | 52 | * |
michael@0 | 53 | * e = (index of last input character matched so far by the pattern) + 1 |
michael@0 | 54 | * |
michael@0 | 55 | * The match is then attempted from this position in the string (Step 7). |
michael@0 | 56 | * |
michael@0 | 57 | * C. When the global flag IS set and re.lastIndex is < 0 or > str.length, |
michael@0 | 58 | * |lastIndex| is set to 0 and the match returns null. |
michael@0 | 59 | * |
michael@0 | 60 | * |
michael@0 | 61 | * Note the |lastIndex| property is writeable, and may be set arbitrarily |
michael@0 | 62 | * by the programmer - and we will do that below. |
michael@0 | 63 | * |
michael@0 | 64 | */ |
michael@0 | 65 | //----------------------------------------------------------------------------- |
michael@0 | 66 | var i = 0; |
michael@0 | 67 | var BUGNUMBER = 76717; |
michael@0 | 68 | var summary = 'Testing re.exec(str) when re.lastIndex is < 0 or > str.length'; |
michael@0 | 69 | var status = ''; |
michael@0 | 70 | var statusmessages = new Array(); |
michael@0 | 71 | var pattern = ''; |
michael@0 | 72 | var patterns = new Array(); |
michael@0 | 73 | var string = ''; |
michael@0 | 74 | var strings = new Array(); |
michael@0 | 75 | var actualmatch = ''; |
michael@0 | 76 | var actualmatches = new Array(); |
michael@0 | 77 | var expectedmatch = ''; |
michael@0 | 78 | var expectedmatches = new Array(); |
michael@0 | 79 | |
michael@0 | 80 | |
michael@0 | 81 | /****************************************************************************** |
michael@0 | 82 | * |
michael@0 | 83 | * Case 1 : when the global flag is set - |
michael@0 | 84 | * |
michael@0 | 85 | *****************************************************************************/ |
michael@0 | 86 | pattern = /abc/gi; |
michael@0 | 87 | string = 'AbcaBcabC'; |
michael@0 | 88 | |
michael@0 | 89 | status = inSection(1); |
michael@0 | 90 | actualmatch = pattern.exec(string); |
michael@0 | 91 | expectedmatch = Array('Abc'); |
michael@0 | 92 | addThis(); |
michael@0 | 93 | |
michael@0 | 94 | status = inSection(2); |
michael@0 | 95 | actualmatch = pattern.exec(string); |
michael@0 | 96 | expectedmatch = Array('aBc'); |
michael@0 | 97 | addThis(); |
michael@0 | 98 | |
michael@0 | 99 | status = inSection(3); |
michael@0 | 100 | actualmatch = pattern.exec(string); |
michael@0 | 101 | expectedmatch = Array('abC'); |
michael@0 | 102 | addThis(); |
michael@0 | 103 | |
michael@0 | 104 | /* |
michael@0 | 105 | * At this point |lastIndex| is > string.length, so the match should be null - |
michael@0 | 106 | */ |
michael@0 | 107 | status = inSection(4); |
michael@0 | 108 | actualmatch = pattern.exec(string); |
michael@0 | 109 | expectedmatch = null; |
michael@0 | 110 | addThis(); |
michael@0 | 111 | |
michael@0 | 112 | /* |
michael@0 | 113 | * Now let's set |lastIndex| to -1, so the match should again be null - |
michael@0 | 114 | */ |
michael@0 | 115 | status = inSection(5); |
michael@0 | 116 | pattern.lastIndex = -1; |
michael@0 | 117 | actualmatch = pattern.exec(string); |
michael@0 | 118 | expectedmatch = null; |
michael@0 | 119 | addThis(); |
michael@0 | 120 | |
michael@0 | 121 | /* |
michael@0 | 122 | * Now try some edge-case values. Thanks to the work done in |
michael@0 | 123 | * http://bugzilla.mozilla.org/show_bug.cgi?id=124339, |lastIndex| |
michael@0 | 124 | * is now stored as a double instead of a uint32_t (unsigned integer). |
michael@0 | 125 | * |
michael@0 | 126 | * Note 2^32 -1 is the upper bound for uint32's, but doubles can go |
michael@0 | 127 | * all the way up to Number.MAX_VALUE. So that's why we need cases |
michael@0 | 128 | * between those two numbers. |
michael@0 | 129 | */ |
michael@0 | 130 | status = inSection(6); |
michael@0 | 131 | pattern.lastIndex = Math.pow(2,32); |
michael@0 | 132 | actualmatch = pattern.exec(string); |
michael@0 | 133 | expectedmatch = null; |
michael@0 | 134 | addThis(); |
michael@0 | 135 | |
michael@0 | 136 | status = inSection(7); |
michael@0 | 137 | pattern.lastIndex = -Math.pow(2,32); |
michael@0 | 138 | actualmatch = pattern.exec(string); |
michael@0 | 139 | expectedmatch = null; |
michael@0 | 140 | addThis(); |
michael@0 | 141 | |
michael@0 | 142 | status = inSection(8); |
michael@0 | 143 | pattern.lastIndex = Math.pow(2,32) + 1; |
michael@0 | 144 | actualmatch = pattern.exec(string); |
michael@0 | 145 | expectedmatch = null; |
michael@0 | 146 | addThis(); |
michael@0 | 147 | |
michael@0 | 148 | status = inSection(9); |
michael@0 | 149 | pattern.lastIndex = -(Math.pow(2,32) + 1); |
michael@0 | 150 | actualmatch = pattern.exec(string); |
michael@0 | 151 | expectedmatch = null; |
michael@0 | 152 | addThis(); |
michael@0 | 153 | |
michael@0 | 154 | status = inSection(10); |
michael@0 | 155 | pattern.lastIndex = Math.pow(2,32) * 2; |
michael@0 | 156 | actualmatch = pattern.exec(string); |
michael@0 | 157 | expectedmatch = null; |
michael@0 | 158 | addThis(); |
michael@0 | 159 | |
michael@0 | 160 | status = inSection(11); |
michael@0 | 161 | pattern.lastIndex = -Math.pow(2,32) * 2; |
michael@0 | 162 | actualmatch = pattern.exec(string); |
michael@0 | 163 | expectedmatch = null; |
michael@0 | 164 | addThis(); |
michael@0 | 165 | |
michael@0 | 166 | status = inSection(12); |
michael@0 | 167 | pattern.lastIndex = Math.pow(2,40); |
michael@0 | 168 | actualmatch = pattern.exec(string); |
michael@0 | 169 | expectedmatch = null; |
michael@0 | 170 | addThis(); |
michael@0 | 171 | |
michael@0 | 172 | status = inSection(13); |
michael@0 | 173 | pattern.lastIndex = -Math.pow(2,40); |
michael@0 | 174 | actualmatch = pattern.exec(string); |
michael@0 | 175 | expectedmatch = null; |
michael@0 | 176 | addThis(); |
michael@0 | 177 | |
michael@0 | 178 | status = inSection(14); |
michael@0 | 179 | pattern.lastIndex = Number.MAX_VALUE; |
michael@0 | 180 | actualmatch = pattern.exec(string); |
michael@0 | 181 | expectedmatch = null; |
michael@0 | 182 | addThis(); |
michael@0 | 183 | |
michael@0 | 184 | status = inSection(15); |
michael@0 | 185 | pattern.lastIndex = -Number.MAX_VALUE; |
michael@0 | 186 | actualmatch = pattern.exec(string); |
michael@0 | 187 | expectedmatch = null; |
michael@0 | 188 | addThis(); |
michael@0 | 189 | |
michael@0 | 190 | |
michael@0 | 191 | |
michael@0 | 192 | /****************************************************************************** |
michael@0 | 193 | * |
michael@0 | 194 | * Case 2: repeat all the above cases WITHOUT the global flag set. |
michael@0 | 195 | * According to EMCA. |lastIndex| should get set to 0 before the match. |
michael@0 | 196 | * |
michael@0 | 197 | * Therefore re.exec(str) should be unaffected; thus our expected values |
michael@0 | 198 | * below are now DIFFERENT when |lastIndex| is < 0 or > str.length |
michael@0 | 199 | * |
michael@0 | 200 | *****************************************************************************/ |
michael@0 | 201 | |
michael@0 | 202 | pattern = /abc/i; |
michael@0 | 203 | string = 'AbcaBcabC'; |
michael@0 | 204 | |
michael@0 | 205 | status = inSection(16); |
michael@0 | 206 | actualmatch = pattern.exec(string); |
michael@0 | 207 | expectedmatch = Array('Abc'); |
michael@0 | 208 | addThis(); |
michael@0 | 209 | |
michael@0 | 210 | status = inSection(17); |
michael@0 | 211 | actualmatch = pattern.exec(string); |
michael@0 | 212 | expectedmatch = Array('Abc'); // NOT Array('aBc') as before - |
michael@0 | 213 | addThis(); |
michael@0 | 214 | |
michael@0 | 215 | status = inSection(18); |
michael@0 | 216 | actualmatch = pattern.exec(string); |
michael@0 | 217 | expectedmatch = Array('Abc'); // NOT Array('abC') as before - |
michael@0 | 218 | addThis(); |
michael@0 | 219 | |
michael@0 | 220 | /* |
michael@0 | 221 | * At this point above, |lastIndex| WAS > string.length, but not here - |
michael@0 | 222 | */ |
michael@0 | 223 | status = inSection(19); |
michael@0 | 224 | actualmatch = pattern.exec(string); |
michael@0 | 225 | expectedmatch = Array('Abc') // NOT null as before - |
michael@0 | 226 | addThis(); |
michael@0 | 227 | |
michael@0 | 228 | /* |
michael@0 | 229 | * Now let's set |lastIndex| to -1 |
michael@0 | 230 | */ |
michael@0 | 231 | status = inSection(20); |
michael@0 | 232 | pattern.lastIndex = -1; |
michael@0 | 233 | actualmatch = pattern.exec(string); |
michael@0 | 234 | expectedmatch = Array('Abc') // NOT null as before - |
michael@0 | 235 | addThis(); |
michael@0 | 236 | |
michael@0 | 237 | /* |
michael@0 | 238 | * Now try some edge-case values. Thanks to the work done in |
michael@0 | 239 | * http://bugzilla.mozilla.org/show_bug.cgi?id=124339, |lastIndex| |
michael@0 | 240 | * is now stored as a double instead of a uint32_t (unsigned integer). |
michael@0 | 241 | * |
michael@0 | 242 | * Note 2^32 -1 is the upper bound for uint32's, but doubles can go |
michael@0 | 243 | * all the way up to Number.MAX_VALUE. So that's why we need cases |
michael@0 | 244 | * between those two numbers. |
michael@0 | 245 | */ |
michael@0 | 246 | status = inSection(21); |
michael@0 | 247 | pattern.lastIndex = Math.pow(2,32); |
michael@0 | 248 | actualmatch = pattern.exec(string); |
michael@0 | 249 | expectedmatch = Array('Abc') // NOT null as before - |
michael@0 | 250 | addThis(); |
michael@0 | 251 | |
michael@0 | 252 | status = inSection(22); |
michael@0 | 253 | pattern.lastIndex = -Math.pow(2,32); |
michael@0 | 254 | actualmatch = pattern.exec(string); |
michael@0 | 255 | expectedmatch = Array('Abc') // NOT null as before - |
michael@0 | 256 | addThis(); |
michael@0 | 257 | |
michael@0 | 258 | status = inSection(23); |
michael@0 | 259 | pattern.lastIndex = Math.pow(2,32) + 1; |
michael@0 | 260 | actualmatch = pattern.exec(string); |
michael@0 | 261 | expectedmatch = Array('Abc') // NOT null as before - |
michael@0 | 262 | addThis(); |
michael@0 | 263 | |
michael@0 | 264 | status = inSection(24); |
michael@0 | 265 | pattern.lastIndex = -(Math.pow(2,32) + 1); |
michael@0 | 266 | actualmatch = pattern.exec(string); |
michael@0 | 267 | expectedmatch = Array('Abc') // NOT null as before - |
michael@0 | 268 | addThis(); |
michael@0 | 269 | |
michael@0 | 270 | status = inSection(25); |
michael@0 | 271 | pattern.lastIndex = Math.pow(2,32) * 2; |
michael@0 | 272 | actualmatch = pattern.exec(string); |
michael@0 | 273 | expectedmatch = Array('Abc') // NOT null as before - |
michael@0 | 274 | addThis(); |
michael@0 | 275 | |
michael@0 | 276 | status = inSection(26); |
michael@0 | 277 | pattern.lastIndex = -Math.pow(2,32) * 2; |
michael@0 | 278 | actualmatch = pattern.exec(string); |
michael@0 | 279 | expectedmatch = Array('Abc') // NOT null as before - |
michael@0 | 280 | addThis(); |
michael@0 | 281 | |
michael@0 | 282 | status = inSection(27); |
michael@0 | 283 | pattern.lastIndex = Math.pow(2,40); |
michael@0 | 284 | actualmatch = pattern.exec(string); |
michael@0 | 285 | expectedmatch = Array('Abc') // NOT null as before -; |
michael@0 | 286 | addThis(); |
michael@0 | 287 | |
michael@0 | 288 | status = inSection(28); |
michael@0 | 289 | pattern.lastIndex = -Math.pow(2,40); |
michael@0 | 290 | actualmatch = pattern.exec(string); |
michael@0 | 291 | expectedmatch = Array('Abc') // NOT null as before - |
michael@0 | 292 | addThis(); |
michael@0 | 293 | |
michael@0 | 294 | status = inSection(29); |
michael@0 | 295 | pattern.lastIndex = Number.MAX_VALUE; |
michael@0 | 296 | actualmatch = pattern.exec(string); |
michael@0 | 297 | expectedmatch = Array('Abc') // NOT null as before - |
michael@0 | 298 | addThis(); |
michael@0 | 299 | |
michael@0 | 300 | status = inSection(30); |
michael@0 | 301 | pattern.lastIndex = -Number.MAX_VALUE; |
michael@0 | 302 | actualmatch = pattern.exec(string); |
michael@0 | 303 | expectedmatch = Array('Abc') // NOT null as before - |
michael@0 | 304 | addThis(); |
michael@0 | 305 | |
michael@0 | 306 | |
michael@0 | 307 | |
michael@0 | 308 | |
michael@0 | 309 | //------------------------------------------------------------------------------------------------- |
michael@0 | 310 | test(); |
michael@0 | 311 | //------------------------------------------------------------------------------------------------- |
michael@0 | 312 | |
michael@0 | 313 | |
michael@0 | 314 | |
michael@0 | 315 | function addThis() |
michael@0 | 316 | { |
michael@0 | 317 | statusmessages[i] = status; |
michael@0 | 318 | patterns[i] = pattern; |
michael@0 | 319 | strings[i] = string; |
michael@0 | 320 | actualmatches[i] = actualmatch; |
michael@0 | 321 | expectedmatches[i] = expectedmatch; |
michael@0 | 322 | i++; |
michael@0 | 323 | } |
michael@0 | 324 | |
michael@0 | 325 | |
michael@0 | 326 | function test() |
michael@0 | 327 | { |
michael@0 | 328 | enterFunc ('test'); |
michael@0 | 329 | printBugNumber(BUGNUMBER); |
michael@0 | 330 | printStatus (summary); |
michael@0 | 331 | testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches); |
michael@0 | 332 | exitFunc ('test'); |
michael@0 | 333 | } |