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: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
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: 12 December 2003 |
michael@0 | 9 | * SUMMARY: Testing regexps with unescaped braces |
michael@0 | 10 | * See http://bugzilla.mozilla.org/show_bug.cgi?id=228087 |
michael@0 | 11 | * |
michael@0 | 12 | * Note: unbalanced, unescaped braces are not permitted by ECMA-262 Ed.3, |
michael@0 | 13 | * but we decided to follow Perl and IE and allow this for compatibility. |
michael@0 | 14 | * |
michael@0 | 15 | * See http://bugzilla.mozilla.org/show_bug.cgi?id=188206 and its testcase. |
michael@0 | 16 | * See http://bugzilla.mozilla.org/show_bug.cgi?id=223273 and its testcase. |
michael@0 | 17 | */ |
michael@0 | 18 | //----------------------------------------------------------------------------- |
michael@0 | 19 | var i = 0; |
michael@0 | 20 | var BUGNUMBER = 228087; |
michael@0 | 21 | var summary = 'Testing regexps with unescaped braces'; |
michael@0 | 22 | var status = ''; |
michael@0 | 23 | var statusmessages = new Array(); |
michael@0 | 24 | var pattern = ''; |
michael@0 | 25 | var patterns = new Array(); |
michael@0 | 26 | var string = ''; |
michael@0 | 27 | var strings = new Array(); |
michael@0 | 28 | var actualmatch = ''; |
michael@0 | 29 | var actualmatches = new Array(); |
michael@0 | 30 | var expectedmatch = ''; |
michael@0 | 31 | var expectedmatches = new Array(); |
michael@0 | 32 | var e; |
michael@0 | 33 | |
michael@0 | 34 | |
michael@0 | 35 | string = 'foo {1} foo {2} foo'; |
michael@0 | 36 | |
michael@0 | 37 | // try an example with the braces escaped |
michael@0 | 38 | status = inSection(1); |
michael@0 | 39 | try |
michael@0 | 40 | { |
michael@0 | 41 | pattern = new RegExp('\{1.*\}', 'g'); |
michael@0 | 42 | actualmatch = string.match(pattern); |
michael@0 | 43 | } |
michael@0 | 44 | catch (e) |
michael@0 | 45 | { |
michael@0 | 46 | pattern = 'error'; |
michael@0 | 47 | actualmatch = ''; |
michael@0 | 48 | } |
michael@0 | 49 | expectedmatch = Array('{1} foo {2}'); |
michael@0 | 50 | addThis(); |
michael@0 | 51 | |
michael@0 | 52 | // just like Section 1, without the braces being escaped |
michael@0 | 53 | status = inSection(2); |
michael@0 | 54 | try |
michael@0 | 55 | { |
michael@0 | 56 | pattern = new RegExp('{1.*}', 'g'); |
michael@0 | 57 | actualmatch = string.match(pattern); |
michael@0 | 58 | } |
michael@0 | 59 | catch (e) |
michael@0 | 60 | { |
michael@0 | 61 | pattern = 'error'; |
michael@0 | 62 | actualmatch = ''; |
michael@0 | 63 | } |
michael@0 | 64 | expectedmatch = Array('{1} foo {2}'); |
michael@0 | 65 | addThis(); |
michael@0 | 66 | |
michael@0 | 67 | // try an example with the braces escaped |
michael@0 | 68 | status = inSection(3); |
michael@0 | 69 | try |
michael@0 | 70 | { |
michael@0 | 71 | pattern = new RegExp('\{1[.!\}]*\}', 'g'); |
michael@0 | 72 | actualmatch = string.match(pattern); |
michael@0 | 73 | } |
michael@0 | 74 | catch (e) |
michael@0 | 75 | { |
michael@0 | 76 | pattern = 'error'; |
michael@0 | 77 | actualmatch = ''; |
michael@0 | 78 | } |
michael@0 | 79 | expectedmatch = Array('{1}'); |
michael@0 | 80 | addThis(); |
michael@0 | 81 | |
michael@0 | 82 | // just like Section 3, without the braces being escaped |
michael@0 | 83 | status = inSection(4); |
michael@0 | 84 | try |
michael@0 | 85 | { |
michael@0 | 86 | pattern = new RegExp('{1[.!}]*}', 'g'); |
michael@0 | 87 | actualmatch = string.match(pattern); |
michael@0 | 88 | } |
michael@0 | 89 | catch (e) |
michael@0 | 90 | { |
michael@0 | 91 | pattern = 'error'; |
michael@0 | 92 | actualmatch = ''; |
michael@0 | 93 | } |
michael@0 | 94 | expectedmatch = Array('{1}'); |
michael@0 | 95 | addThis(); |
michael@0 | 96 | |
michael@0 | 97 | |
michael@0 | 98 | string = 'abccccc{3 }c{ 3}c{3, }c{3 ,}c{3 ,4}c{3, 4}c{3,4 }de'; |
michael@0 | 99 | |
michael@0 | 100 | // use braces in a normal quantifier construct |
michael@0 | 101 | status = inSection(5); |
michael@0 | 102 | try |
michael@0 | 103 | { |
michael@0 | 104 | pattern = new RegExp('c{3}'); |
michael@0 | 105 | actualmatch = string.match(pattern); |
michael@0 | 106 | } |
michael@0 | 107 | catch (e) |
michael@0 | 108 | { |
michael@0 | 109 | pattern = 'error'; |
michael@0 | 110 | actualmatch = ''; |
michael@0 | 111 | } |
michael@0 | 112 | expectedmatch = Array('ccc'); |
michael@0 | 113 | addThis(); |
michael@0 | 114 | |
michael@0 | 115 | // now disrupt the quantifer - the braces should now be interpreted literally |
michael@0 | 116 | status = inSection(6); |
michael@0 | 117 | try |
michael@0 | 118 | { |
michael@0 | 119 | pattern = new RegExp('c{3 }'); |
michael@0 | 120 | actualmatch = string.match(pattern); |
michael@0 | 121 | } |
michael@0 | 122 | catch (e) |
michael@0 | 123 | { |
michael@0 | 124 | pattern = 'error'; |
michael@0 | 125 | actualmatch = ''; |
michael@0 | 126 | } |
michael@0 | 127 | expectedmatch = Array('c{3 }'); |
michael@0 | 128 | addThis(); |
michael@0 | 129 | |
michael@0 | 130 | status = inSection(7); |
michael@0 | 131 | try |
michael@0 | 132 | { |
michael@0 | 133 | pattern = new RegExp('c{3.}'); |
michael@0 | 134 | actualmatch = string.match(pattern); |
michael@0 | 135 | } |
michael@0 | 136 | catch (e) |
michael@0 | 137 | { |
michael@0 | 138 | pattern = 'error'; |
michael@0 | 139 | actualmatch = ''; |
michael@0 | 140 | } |
michael@0 | 141 | expectedmatch = Array('c{3 }'); |
michael@0 | 142 | addThis(); |
michael@0 | 143 | |
michael@0 | 144 | status = inSection(8); |
michael@0 | 145 | try |
michael@0 | 146 | { |
michael@0 | 147 | // need to escape the \ in \s since |
michael@0 | 148 | // this has been converted to a constructor call |
michael@0 | 149 | // instead of a literal regexp |
michael@0 | 150 | pattern = new RegExp('c{3\\s}'); |
michael@0 | 151 | actualmatch = string.match(pattern); |
michael@0 | 152 | } |
michael@0 | 153 | catch (e) |
michael@0 | 154 | { |
michael@0 | 155 | pattern = 'error'; |
michael@0 | 156 | actualmatch = ''; |
michael@0 | 157 | } |
michael@0 | 158 | expectedmatch = Array('c{3 }'); |
michael@0 | 159 | addThis(); |
michael@0 | 160 | |
michael@0 | 161 | status = inSection(9); |
michael@0 | 162 | try |
michael@0 | 163 | { |
michael@0 | 164 | pattern = new RegExp('c{3[ ]}'); |
michael@0 | 165 | actualmatch = string.match(pattern); |
michael@0 | 166 | } |
michael@0 | 167 | catch (e) |
michael@0 | 168 | { |
michael@0 | 169 | pattern = 'error'; |
michael@0 | 170 | actualmatch = ''; |
michael@0 | 171 | } |
michael@0 | 172 | expectedmatch = Array('c{3 }'); |
michael@0 | 173 | addThis(); |
michael@0 | 174 | |
michael@0 | 175 | status = inSection(10); |
michael@0 | 176 | try |
michael@0 | 177 | { |
michael@0 | 178 | pattern = new RegExp('c{ 3}'); |
michael@0 | 179 | actualmatch = string.match(pattern); |
michael@0 | 180 | } |
michael@0 | 181 | catch (e) |
michael@0 | 182 | { |
michael@0 | 183 | pattern = 'error'; |
michael@0 | 184 | actualmatch = ''; |
michael@0 | 185 | } |
michael@0 | 186 | expectedmatch = Array('c{ 3}'); |
michael@0 | 187 | addThis(); |
michael@0 | 188 | |
michael@0 | 189 | // using braces in a normal quantifier construct again |
michael@0 | 190 | status = inSection(11); |
michael@0 | 191 | try |
michael@0 | 192 | { |
michael@0 | 193 | pattern = new RegExp('c{3,}'); |
michael@0 | 194 | actualmatch = string.match(pattern); |
michael@0 | 195 | } |
michael@0 | 196 | catch (e) |
michael@0 | 197 | { |
michael@0 | 198 | pattern = 'error'; |
michael@0 | 199 | actualmatch = ''; |
michael@0 | 200 | } |
michael@0 | 201 | expectedmatch = Array('ccccc'); |
michael@0 | 202 | addThis(); |
michael@0 | 203 | |
michael@0 | 204 | // now disrupt it - the braces should now be interpreted literally |
michael@0 | 205 | status = inSection(12); |
michael@0 | 206 | try |
michael@0 | 207 | { |
michael@0 | 208 | pattern = new RegExp('c{3, }'); |
michael@0 | 209 | actualmatch = string.match(pattern); |
michael@0 | 210 | } |
michael@0 | 211 | catch (e) |
michael@0 | 212 | { |
michael@0 | 213 | pattern = 'error'; |
michael@0 | 214 | actualmatch = ''; |
michael@0 | 215 | } |
michael@0 | 216 | expectedmatch = Array('c{3, }'); |
michael@0 | 217 | addThis(); |
michael@0 | 218 | |
michael@0 | 219 | status = inSection(13); |
michael@0 | 220 | try |
michael@0 | 221 | { |
michael@0 | 222 | pattern = new RegExp('c{3 ,}'); |
michael@0 | 223 | actualmatch = string.match(pattern); |
michael@0 | 224 | } |
michael@0 | 225 | catch (e) |
michael@0 | 226 | { |
michael@0 | 227 | pattern = 'error'; |
michael@0 | 228 | actualmatch = ''; |
michael@0 | 229 | } |
michael@0 | 230 | expectedmatch = Array('c{3 ,}'); |
michael@0 | 231 | addThis(); |
michael@0 | 232 | |
michael@0 | 233 | // using braces in a normal quantifier construct again |
michael@0 | 234 | status = inSection(14); |
michael@0 | 235 | try |
michael@0 | 236 | { |
michael@0 | 237 | pattern = new RegExp('c{3,4}'); |
michael@0 | 238 | actualmatch = string.match(pattern); |
michael@0 | 239 | } |
michael@0 | 240 | catch (e) |
michael@0 | 241 | { |
michael@0 | 242 | pattern = 'error'; |
michael@0 | 243 | actualmatch = ''; |
michael@0 | 244 | } |
michael@0 | 245 | expectedmatch = Array('cccc'); |
michael@0 | 246 | addThis(); |
michael@0 | 247 | |
michael@0 | 248 | // now disrupt it - the braces should now be interpreted literally |
michael@0 | 249 | status = inSection(15); |
michael@0 | 250 | try |
michael@0 | 251 | { |
michael@0 | 252 | pattern = new RegExp('c{3 ,4}'); |
michael@0 | 253 | actualmatch = string.match(pattern); |
michael@0 | 254 | } |
michael@0 | 255 | catch (e) |
michael@0 | 256 | { |
michael@0 | 257 | pattern = 'error'; |
michael@0 | 258 | actualmatch = ''; |
michael@0 | 259 | } |
michael@0 | 260 | expectedmatch = Array('c{3 ,4}'); |
michael@0 | 261 | addThis(); |
michael@0 | 262 | |
michael@0 | 263 | status = inSection(16); |
michael@0 | 264 | try |
michael@0 | 265 | { |
michael@0 | 266 | pattern = new RegExp('c{3, 4}'); |
michael@0 | 267 | actualmatch = string.match(pattern); |
michael@0 | 268 | } |
michael@0 | 269 | catch (e) |
michael@0 | 270 | { |
michael@0 | 271 | pattern = 'error'; |
michael@0 | 272 | actualmatch = ''; |
michael@0 | 273 | } |
michael@0 | 274 | expectedmatch = Array('c{3, 4}'); |
michael@0 | 275 | addThis(); |
michael@0 | 276 | |
michael@0 | 277 | status = inSection(17); |
michael@0 | 278 | try |
michael@0 | 279 | { |
michael@0 | 280 | pattern = new RegExp('c{3,4 }'); |
michael@0 | 281 | actualmatch = string.match(pattern); |
michael@0 | 282 | } |
michael@0 | 283 | catch (e) |
michael@0 | 284 | { |
michael@0 | 285 | pattern = 'error'; |
michael@0 | 286 | actualmatch = ''; |
michael@0 | 287 | } |
michael@0 | 288 | expectedmatch = Array('c{3,4 }'); |
michael@0 | 289 | addThis(); |
michael@0 | 290 | |
michael@0 | 291 | |
michael@0 | 292 | |
michael@0 | 293 | |
michael@0 | 294 | //------------------------------------------------------------------------------------------------- |
michael@0 | 295 | test(); |
michael@0 | 296 | //------------------------------------------------------------------------------------------------- |
michael@0 | 297 | |
michael@0 | 298 | |
michael@0 | 299 | |
michael@0 | 300 | function addThis() |
michael@0 | 301 | { |
michael@0 | 302 | statusmessages[i] = status; |
michael@0 | 303 | patterns[i] = pattern; |
michael@0 | 304 | strings[i] = string; |
michael@0 | 305 | actualmatches[i] = actualmatch; |
michael@0 | 306 | expectedmatches[i] = expectedmatch; |
michael@0 | 307 | i++; |
michael@0 | 308 | } |
michael@0 | 309 | |
michael@0 | 310 | |
michael@0 | 311 | function test() |
michael@0 | 312 | { |
michael@0 | 313 | enterFunc ('test'); |
michael@0 | 314 | printBugNumber(BUGNUMBER); |
michael@0 | 315 | printStatus (summary); |
michael@0 | 316 | testRegExp(statusmessages, patterns, strings, actualmatches, expectedmatches); |
michael@0 | 317 | exitFunc ('test'); |
michael@0 | 318 | } |