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: 31 July 2002 |
michael@0 | 9 | * SUMMARY: Testing regexps containing octal escape sequences |
michael@0 | 10 | * This is an elaboration of mozilla/js/tests/ecma_2/RegExp/octal-003.js |
michael@0 | 11 | * |
michael@0 | 12 | * See http://bugzilla.mozilla.org/show_bug.cgi?id=141078 |
michael@0 | 13 | * for a reference on octal escape sequences in regexps. |
michael@0 | 14 | * |
michael@0 | 15 | * NOTE: |
michael@0 | 16 | * We will use the identities '\011' === '\u0009' === '\x09' === '\t' |
michael@0 | 17 | * |
michael@0 | 18 | * The first is an octal escape sequence (\(0-3)OO; O an octal digit). |
michael@0 | 19 | * See ECMA-262 Edition 2, Section 7.7.4 "String Literals". These were |
michael@0 | 20 | * dropped in Edition 3 but we support them for backward compatibility. |
michael@0 | 21 | * |
michael@0 | 22 | * The second is a Unicode escape sequence (\uHHHH; H a hex digit). |
michael@0 | 23 | * Since octal 11 = hex 9, the two escapes define the same character. |
michael@0 | 24 | * |
michael@0 | 25 | * The third is a hex escape sequence (\xHH; H a hex digit). |
michael@0 | 26 | * Since hex 09 = hex 0009, this defines the same character. |
michael@0 | 27 | * |
michael@0 | 28 | * The fourth is the familiar escape sequence for a horizontal tab, |
michael@0 | 29 | * defined in the ECMA spec as having Unicode value \u0009. |
michael@0 | 30 | */ |
michael@0 | 31 | //----------------------------------------------------------------------------- |
michael@0 | 32 | var i = 0; |
michael@0 | 33 | var BUGNUMBER = 141078; |
michael@0 | 34 | var summary = 'Testing regexps containing octal escape sequences'; |
michael@0 | 35 | var status = ''; |
michael@0 | 36 | var statusmessages = new Array(); |
michael@0 | 37 | var pattern = ''; |
michael@0 | 38 | var patterns = new Array(); |
michael@0 | 39 | var string = ''; |
michael@0 | 40 | var strings = new Array(); |
michael@0 | 41 | var actualmatch = ''; |
michael@0 | 42 | var actualmatches = new Array(); |
michael@0 | 43 | var expectedmatch = ''; |
michael@0 | 44 | var expectedmatches = new Array(); |
michael@0 | 45 | |
michael@0 | 46 | |
michael@0 | 47 | /* |
michael@0 | 48 | * Test a string containing the null character '\0' followed by the string '11' |
michael@0 | 49 | * |
michael@0 | 50 | * 'a' + String.fromCharCode(0) + '11'; |
michael@0 | 51 | * |
michael@0 | 52 | * Note we can't simply write 'a\011', because '\011' would be interpreted |
michael@0 | 53 | * as the octal escape sequence for the tab character (see above). |
michael@0 | 54 | * |
michael@0 | 55 | * We should get no match from the regexp /.\011/, because it should be |
michael@0 | 56 | * looking for the octal escape sequence \011, i.e. the tab character - |
michael@0 | 57 | * |
michael@0 | 58 | */ |
michael@0 | 59 | status = inSection(1); |
michael@0 | 60 | pattern = /.\011/; |
michael@0 | 61 | string = 'a' + String.fromCharCode(0) + '11'; |
michael@0 | 62 | actualmatch = string.match(pattern); |
michael@0 | 63 | expectedmatch = null; |
michael@0 | 64 | addThis(); |
michael@0 | 65 | |
michael@0 | 66 | |
michael@0 | 67 | /* |
michael@0 | 68 | * Try same thing with 'xx' in place of '11'. |
michael@0 | 69 | * |
michael@0 | 70 | * Should get a match now, because the octal escape sequence in the regexp |
michael@0 | 71 | * has been reduced from \011 to \0, and '\0' is present in the string - |
michael@0 | 72 | */ |
michael@0 | 73 | status = inSection(2); |
michael@0 | 74 | pattern = /.\0xx/; |
michael@0 | 75 | string = 'a' + String.fromCharCode(0) + 'xx'; |
michael@0 | 76 | actualmatch = string.match(pattern); |
michael@0 | 77 | expectedmatch = Array(string); |
michael@0 | 78 | addThis(); |
michael@0 | 79 | |
michael@0 | 80 | |
michael@0 | 81 | /* |
michael@0 | 82 | * Same thing; don't use |String.fromCharCode(0)| this time. |
michael@0 | 83 | * There is no ambiguity in '\0xx': it is the null character |
michael@0 | 84 | * followed by two x's, no other interpretation is possible. |
michael@0 | 85 | */ |
michael@0 | 86 | status = inSection(3); |
michael@0 | 87 | pattern = /.\0xx/; |
michael@0 | 88 | string = 'a\0xx'; |
michael@0 | 89 | actualmatch = string.match(pattern); |
michael@0 | 90 | expectedmatch = Array(string); |
michael@0 | 91 | addThis(); |
michael@0 | 92 | |
michael@0 | 93 | |
michael@0 | 94 | /* |
michael@0 | 95 | * This one should produce a match. The two-character string |
michael@0 | 96 | * 'a' + '\011' is duplicated in the pattern and test string: |
michael@0 | 97 | */ |
michael@0 | 98 | status = inSection(4); |
michael@0 | 99 | pattern = /.\011/; |
michael@0 | 100 | string = 'a\011'; |
michael@0 | 101 | actualmatch = string.match(pattern); |
michael@0 | 102 | expectedmatch = Array(string); |
michael@0 | 103 | addThis(); |
michael@0 | 104 | |
michael@0 | 105 | |
michael@0 | 106 | /* |
michael@0 | 107 | * Same as above, only now, for the second character of the string, |
michael@0 | 108 | * use the Unicode escape '\u0009' instead of the octal escape '\011' |
michael@0 | 109 | */ |
michael@0 | 110 | status = inSection(5); |
michael@0 | 111 | pattern = /.\011/; |
michael@0 | 112 | string = 'a\u0009'; |
michael@0 | 113 | actualmatch = string.match(pattern); |
michael@0 | 114 | expectedmatch = Array(string); |
michael@0 | 115 | addThis(); |
michael@0 | 116 | |
michael@0 | 117 | |
michael@0 | 118 | /* |
michael@0 | 119 | * Same as above, only now for the second character of the string, |
michael@0 | 120 | * use the hex escape '\x09' instead of the octal escape '\011' |
michael@0 | 121 | */ |
michael@0 | 122 | status = inSection(6); |
michael@0 | 123 | pattern = /.\011/; |
michael@0 | 124 | string = 'a\x09'; |
michael@0 | 125 | actualmatch = string.match(pattern); |
michael@0 | 126 | expectedmatch = Array(string); |
michael@0 | 127 | addThis(); |
michael@0 | 128 | |
michael@0 | 129 | |
michael@0 | 130 | /* |
michael@0 | 131 | * Same as above, only now for the second character of the string, |
michael@0 | 132 | * use the escape '\t' instead of the octal escape '\011' |
michael@0 | 133 | */ |
michael@0 | 134 | status = inSection(7); |
michael@0 | 135 | pattern = /.\011/; |
michael@0 | 136 | string = 'a\t'; |
michael@0 | 137 | actualmatch = string.match(pattern); |
michael@0 | 138 | expectedmatch = Array(string); |
michael@0 | 139 | addThis(); |
michael@0 | 140 | |
michael@0 | 141 | |
michael@0 | 142 | /* |
michael@0 | 143 | * Return to the string from Section 1. |
michael@0 | 144 | * |
michael@0 | 145 | * Unlike Section 1, use the RegExp() function to create the |
michael@0 | 146 | * regexp pattern: null character followed by the string '11'. |
michael@0 | 147 | * |
michael@0 | 148 | * Since this is exactly what the string is, we should get a match - |
michael@0 | 149 | */ |
michael@0 | 150 | status = inSection(8); |
michael@0 | 151 | string = 'a' + String.fromCharCode(0) + '11'; |
michael@0 | 152 | pattern = RegExp(string); |
michael@0 | 153 | actualmatch = string.match(pattern); |
michael@0 | 154 | expectedmatch = Array(string); |
michael@0 | 155 | addThis(); |
michael@0 | 156 | |
michael@0 | 157 | |
michael@0 | 158 | |
michael@0 | 159 | |
michael@0 | 160 | //------------------------------------------------------------------------------------------------- |
michael@0 | 161 | test(); |
michael@0 | 162 | //------------------------------------------------------------------------------------------------- |
michael@0 | 163 | |
michael@0 | 164 | |
michael@0 | 165 | |
michael@0 | 166 | function addThis() |
michael@0 | 167 | { |
michael@0 | 168 | statusmessages[i] = status; |
michael@0 | 169 | patterns[i] = pattern; |
michael@0 | 170 | strings[i] = string; |
michael@0 | 171 | actualmatches[i] = actualmatch; |
michael@0 | 172 | expectedmatches[i] = expectedmatch; |
michael@0 | 173 | i++; |
michael@0 | 174 | } |
michael@0 | 175 | |
michael@0 | 176 | |
michael@0 | 177 | function test() |
michael@0 | 178 | { |
michael@0 | 179 | enterFunc ('test'); |
michael@0 | 180 | printBugNumber(BUGNUMBER); |
michael@0 | 181 | printStatus (summary); |
michael@0 | 182 | testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches); |
michael@0 | 183 | exitFunc ('test'); |
michael@0 | 184 | } |