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 | * Date: 23 October 2001 |
michael@0 | 8 | * |
michael@0 | 9 | * SUMMARY: Testing regexps with the global flag set. |
michael@0 | 10 | * NOT every substring fitting the given pattern will be matched. |
michael@0 | 11 | * The parent string is CONSUMED as successive matches are found. |
michael@0 | 12 | * |
michael@0 | 13 | * From the ECMA-262 Final spec: |
michael@0 | 14 | * |
michael@0 | 15 | * 15.10.6.2 RegExp.prototype.exec(string) |
michael@0 | 16 | * Performs a regular expression match of string against the regular |
michael@0 | 17 | * expression and returns an Array object containing the results of |
michael@0 | 18 | * the match, or null if the string did not match. |
michael@0 | 19 | * |
michael@0 | 20 | * The string ToString(string) is searched for an occurrence of the |
michael@0 | 21 | * regular expression pattern as follows: |
michael@0 | 22 | * |
michael@0 | 23 | * 1. Let S be the value of ToString(string). |
michael@0 | 24 | * 2. Let length be the length of S. |
michael@0 | 25 | * 3. Let lastIndex be the value of the lastIndex property. |
michael@0 | 26 | * 4. Let i be the value of ToInteger(lastIndex). |
michael@0 | 27 | * 5. If the global property is false, let i = 0. |
michael@0 | 28 | * 6. If i < 0 or i > length then set lastIndex to 0 and return null. |
michael@0 | 29 | * 7. Call [[Match]], giving it the arguments S and i. |
michael@0 | 30 | * If [[Match]] returned failure, go to step 8; |
michael@0 | 31 | * otherwise let r be its State result and go to step 10. |
michael@0 | 32 | * 8. Let i = i+1. |
michael@0 | 33 | * 9. Go to step 6. |
michael@0 | 34 | * 10. Let e be r's endIndex value. |
michael@0 | 35 | * 11. If the global property is true, set lastIndex to e. |
michael@0 | 36 | * |
michael@0 | 37 | * etc. |
michael@0 | 38 | * |
michael@0 | 39 | * |
michael@0 | 40 | * So when the global flag is set, |lastIndex| is incremented every time |
michael@0 | 41 | * there is a match; not from i to i+1, but from i to "endIndex" e: |
michael@0 | 42 | * |
michael@0 | 43 | * e = (index of last input character matched so far by the pattern) + 1 |
michael@0 | 44 | * |
michael@0 | 45 | * Thus in the example below, the first endIndex e occurs after the |
michael@0 | 46 | * first match 'a b'. The next match will begin AFTER this, and so |
michael@0 | 47 | * will NOT be 'b c', but rather 'c d'. Similarly, 'd e' won't be matched. |
michael@0 | 48 | */ |
michael@0 | 49 | //----------------------------------------------------------------------------- |
michael@0 | 50 | var i = 0; |
michael@0 | 51 | var BUGNUMBER = '(none)'; |
michael@0 | 52 | var summary = 'Testing regexps with the global flag set'; |
michael@0 | 53 | var status = ''; |
michael@0 | 54 | var statusmessages = new Array(); |
michael@0 | 55 | var pattern = ''; |
michael@0 | 56 | var patterns = new Array(); |
michael@0 | 57 | var string = ''; |
michael@0 | 58 | var strings = new Array(); |
michael@0 | 59 | var actualmatch = ''; |
michael@0 | 60 | var actualmatches = new Array(); |
michael@0 | 61 | var expectedmatch = ''; |
michael@0 | 62 | var expectedmatches = new Array(); |
michael@0 | 63 | |
michael@0 | 64 | |
michael@0 | 65 | status = inSection(1); |
michael@0 | 66 | string = 'a b c d e'; |
michael@0 | 67 | pattern = /\w\s\w/g; |
michael@0 | 68 | actualmatch = string.match(pattern); |
michael@0 | 69 | expectedmatch = ['a b','c d']; // see above explanation - |
michael@0 | 70 | addThis(); |
michael@0 | 71 | |
michael@0 | 72 | |
michael@0 | 73 | status = inSection(2); |
michael@0 | 74 | string = '12345678'; |
michael@0 | 75 | pattern = /\d\d\d/g; |
michael@0 | 76 | actualmatch = string.match(pattern); |
michael@0 | 77 | expectedmatch = ['123','456']; |
michael@0 | 78 | addThis(); |
michael@0 | 79 | |
michael@0 | 80 | |
michael@0 | 81 | |
michael@0 | 82 | //----------------------------------------------------------------------------- |
michael@0 | 83 | test(); |
michael@0 | 84 | //----------------------------------------------------------------------------- |
michael@0 | 85 | |
michael@0 | 86 | |
michael@0 | 87 | |
michael@0 | 88 | function addThis() |
michael@0 | 89 | { |
michael@0 | 90 | statusmessages[i] = status; |
michael@0 | 91 | patterns[i] = pattern; |
michael@0 | 92 | strings[i] = string; |
michael@0 | 93 | actualmatches[i] = actualmatch; |
michael@0 | 94 | expectedmatches[i] = expectedmatch; |
michael@0 | 95 | i++; |
michael@0 | 96 | } |
michael@0 | 97 | |
michael@0 | 98 | |
michael@0 | 99 | function test() |
michael@0 | 100 | { |
michael@0 | 101 | enterFunc ('test'); |
michael@0 | 102 | printBugNumber(BUGNUMBER); |
michael@0 | 103 | printStatus (summary); |
michael@0 | 104 | testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches); |
michael@0 | 105 | exitFunc ('test'); |
michael@0 | 106 | } |