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: 26 November 2000 |
michael@0 | 8 | * |
michael@0 | 9 | * |
michael@0 | 10 | * SUMMARY: This test arose from Bugzilla bug 57631: |
michael@0 | 11 | * "RegExp with invalid pattern or invalid flag causes segfault" |
michael@0 | 12 | * |
michael@0 | 13 | * Either error should throw an exception of type SyntaxError, |
michael@0 | 14 | * and we check to see that it does... |
michael@0 | 15 | */ |
michael@0 | 16 | //----------------------------------------------------------------------------- |
michael@0 | 17 | var BUGNUMBER = '57631'; |
michael@0 | 18 | var summary = 'Testing new RegExp(pattern,flag) with illegal pattern or flag'; |
michael@0 | 19 | var statprefix = 'Testing for error creating illegal RegExp object on pattern '; |
michael@0 | 20 | var statsuffix = 'and flag '; |
michael@0 | 21 | var cnSUCCESS = 'SyntaxError'; |
michael@0 | 22 | var cnFAILURE = 'not a SyntaxError'; |
michael@0 | 23 | var singlequote = "'"; |
michael@0 | 24 | var i = -1; var j = -1; var s = ''; var f = ''; |
michael@0 | 25 | var obj = {}; |
michael@0 | 26 | var status = ''; var actual = ''; var expect = ''; var msg = ''; |
michael@0 | 27 | var legalpatterns = new Array(); var illegalpatterns = new Array(); |
michael@0 | 28 | var legalflags = new Array(); var illegalflags = new Array(); |
michael@0 | 29 | |
michael@0 | 30 | |
michael@0 | 31 | // valid regular expressions to try - |
michael@0 | 32 | legalpatterns[0] = ''; |
michael@0 | 33 | legalpatterns[1] = 'abc'; |
michael@0 | 34 | legalpatterns[2] = '(.*)(3-1)\s\w'; |
michael@0 | 35 | legalpatterns[3] = '(.*)(...)\\s\\w'; |
michael@0 | 36 | legalpatterns[4] = '[^A-Za-z0-9_]'; |
michael@0 | 37 | legalpatterns[5] = '[^\f\n\r\t\v](123.5)([4 - 8]$)'; |
michael@0 | 38 | |
michael@0 | 39 | // invalid regular expressions to try - |
michael@0 | 40 | illegalpatterns[0] = '(?)'; |
michael@0 | 41 | illegalpatterns[1] = '(a'; |
michael@0 | 42 | illegalpatterns[2] = '( ]'; |
michael@0 | 43 | //illegalpatterns[3] = '\d{1,s}'; |
michael@0 | 44 | |
michael@0 | 45 | // valid flags to try - |
michael@0 | 46 | legalflags[0] = 'i'; |
michael@0 | 47 | legalflags[1] = 'g'; |
michael@0 | 48 | legalflags[2] = 'm'; |
michael@0 | 49 | legalflags[3] = undefined; |
michael@0 | 50 | |
michael@0 | 51 | // invalid flags to try - |
michael@0 | 52 | illegalflags[0] = 'a'; |
michael@0 | 53 | illegalflags[1] = 123; |
michael@0 | 54 | illegalflags[2] = new RegExp(); |
michael@0 | 55 | |
michael@0 | 56 | |
michael@0 | 57 | |
michael@0 | 58 | //------------------------------------------------------------------------------------------------- |
michael@0 | 59 | test(); |
michael@0 | 60 | //------------------------------------------------------------------------------------------------- |
michael@0 | 61 | |
michael@0 | 62 | |
michael@0 | 63 | function test() |
michael@0 | 64 | { |
michael@0 | 65 | enterFunc ('test'); |
michael@0 | 66 | printBugNumber(BUGNUMBER); |
michael@0 | 67 | printStatus (summary); |
michael@0 | 68 | |
michael@0 | 69 | testIllegalRegExps(legalpatterns, illegalflags); |
michael@0 | 70 | testIllegalRegExps(illegalpatterns, legalflags); |
michael@0 | 71 | testIllegalRegExps(illegalpatterns, illegalflags); |
michael@0 | 72 | |
michael@0 | 73 | exitFunc ('test'); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | |
michael@0 | 77 | // This function will only be called where all the patterns are illegal, or all the flags |
michael@0 | 78 | function testIllegalRegExps(patterns, flags) |
michael@0 | 79 | { |
michael@0 | 80 | for (i in patterns) |
michael@0 | 81 | { |
michael@0 | 82 | s = patterns[i]; |
michael@0 | 83 | |
michael@0 | 84 | for (j in flags) |
michael@0 | 85 | { |
michael@0 | 86 | f = flags[j]; |
michael@0 | 87 | status = getStatus(s, f); |
michael@0 | 88 | actual = cnFAILURE; |
michael@0 | 89 | expect = cnSUCCESS; |
michael@0 | 90 | |
michael@0 | 91 | try |
michael@0 | 92 | { |
michael@0 | 93 | // This should cause an exception if either s or f is illegal - |
michael@0 | 94 | eval('obj = new RegExp(s, f);'); |
michael@0 | 95 | } |
michael@0 | 96 | catch(e) |
michael@0 | 97 | { |
michael@0 | 98 | // We expect to get a SyntaxError - test for this: |
michael@0 | 99 | if (e instanceof SyntaxError) |
michael@0 | 100 | actual = cnSUCCESS; |
michael@0 | 101 | } |
michael@0 | 102 | |
michael@0 | 103 | reportCompare(expect, actual, status); |
michael@0 | 104 | } |
michael@0 | 105 | } |
michael@0 | 106 | } |
michael@0 | 107 | |
michael@0 | 108 | |
michael@0 | 109 | function getStatus(regexp, flag) |
michael@0 | 110 | { |
michael@0 | 111 | return (statprefix + quote(regexp) + statsuffix + quote(flag)); |
michael@0 | 112 | } |
michael@0 | 113 | |
michael@0 | 114 | |
michael@0 | 115 | function quote(text) |
michael@0 | 116 | { |
michael@0 | 117 | return (singlequote + text + singlequote); |
michael@0 | 118 | } |