js/src/tests/ecma_3/String/regress-83293.js

Sat, 03 Jan 2015 20:18:00 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Sat, 03 Jan 2015 20:18:00 +0100
branch
TOR_BUG_3246
changeset 7
129ffea94266
permissions
-rw-r--r--

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 * Creation Date: 30 May 2001
michael@0 9 * Correction Date: 14 Aug 2001
michael@0 10 *
michael@0 11 * SUMMARY: Regression test for bugs 83293, 103351
michael@0 12 * See http://bugzilla.mozilla.org/show_bug.cgi?id=83293
michael@0 13 * http://bugzilla.mozilla.org/show_bug.cgi?id=103351
michael@0 14 * http://bugzilla.mozilla.org/show_bug.cgi?id=92942
michael@0 15 *
michael@0 16 *
michael@0 17 * ******************** CORRECTION !!! *****************************
michael@0 18 *
michael@0 19 * When I originally wrote this test, I thought this was true:
michael@0 20 * str.replace(strA, strB) == str.replace(new RegExp(strA),strB).
michael@0 21 * See ECMA-262 Final Draft, 15.5.4.11 String.prototype.replace
michael@0 22 *
michael@0 23 * However, in http://bugzilla.mozilla.org/show_bug.cgi?id=83293
michael@0 24 * Jim Ley points out the ECMA-262 Final Edition changed on this.
michael@0 25 * String.prototype.replace (searchValue, replaceValue), if provided
michael@0 26 * a searchValue that is not a RegExp, is NO LONGER to replace it with
michael@0 27 *
michael@0 28 * new RegExp(searchValue)
michael@0 29 * but rather:
michael@0 30 * String(searchValue)
michael@0 31 *
michael@0 32 * This puts the replace() method at variance with search() and match(),
michael@0 33 * which continue to follow the RegExp conversion of the Final Draft.
michael@0 34 * It also makes most of this testcase, as originally written, invalid.
michael@0 35 **********************************************************************
michael@0 36 */
michael@0 37
michael@0 38 //-----------------------------------------------------------------------------
michael@0 39 var BUGNUMBER = 103351; // <--- (Outgrowth of original bug 83293)
michael@0 40 var summ_OLD = 'Testing str.replace(strA, strB) == str.replace(new RegExp(strA),strB)';
michael@0 41 var summ_NEW = 'Testing String.prototype.replace(x,y) when x is a string';
michael@0 42 var summary = summ_NEW;
michael@0 43 var status = '';
michael@0 44 var actual = '';
michael@0 45 var expect= '';
michael@0 46 var cnEmptyString = '';
michael@0 47 var str = 'abc';
michael@0 48 var strA = cnEmptyString;
michael@0 49 var strB = 'Z';
michael@0 50
michael@0 51
michael@0 52 //-----------------------------------------------------------------------------
michael@0 53 test();
michael@0 54 //-----------------------------------------------------------------------------
michael@0 55
michael@0 56
michael@0 57 /*
michael@0 58 * In this test, it's important to reportCompare() each other case
michael@0 59 * BEFORE the last two cases are attempted. Don't store all results
michael@0 60 * in an array and reportCompare() them at the end, as we usually do.
michael@0 61 *
michael@0 62 * When this bug was filed, str.replace(strA, strB) would return no value
michael@0 63 * whatsoever if strA == cnEmptyString, and no error, either -
michael@0 64 */
michael@0 65 function test()
michael@0 66 {
michael@0 67 enterFunc ('test');
michael@0 68 printBugNumber(BUGNUMBER);
michael@0 69 printStatus (summary);
michael@0 70
michael@0 71 /******************* THESE WERE INCORRECT; SEE ABOVE ************************
michael@0 72 status = 'Section A of test';
michael@0 73 strA = 'a';
michael@0 74 actual = str.replace(strA, strB);
michael@0 75 expect = str.replace(new RegExp(strA), strB);
michael@0 76 reportCompare(expect, actual, status);
michael@0 77
michael@0 78 status = 'Section B of test';
michael@0 79 strA = 'x';
michael@0 80 actual = str.replace(strA, strB);
michael@0 81 expect = str.replace(new RegExp(strA), strB);
michael@0 82 reportCompare(expect, actual, status);
michael@0 83
michael@0 84 status = 'Section C of test';
michael@0 85 strA = undefined;
michael@0 86 actual = str.replace(strA, strB);
michael@0 87 expect = str.replace(new RegExp(strA), strB);
michael@0 88 reportCompare(expect, actual, status);
michael@0 89
michael@0 90 status = 'Section D of test';
michael@0 91 strA = null;
michael@0 92 actual = str.replace(strA, strB);
michael@0 93 expect = str.replace(new RegExp(strA), strB);
michael@0 94 reportCompare(expect, actual, status);
michael@0 95
michael@0 96
michael@0 97 * This example is from jim@jibbering.com (see Bugzilla bug 92942)
michael@0 98 * It is a variation on the example below.
michael@0 99 *
michael@0 100 * Namely, we are using the regexp /$/ instead of the regexp //.
michael@0 101 * The regexp /$/ means we should match the "empty string" at the
michael@0 102 * end-boundary of the word, instead of the one at the beginning.
michael@0 103 *
michael@0 104 status = 'Section E of test';
michael@0 105 var strJim = 'aa$aa';
michael@0 106 strA = '$';
michael@0 107 actual = strJim.replace(strA, strB); // bug -> 'aaZaa'
michael@0 108 expect = strJim.replace(new RegExp(strA), strB); // expect 'aa$aaZ'
michael@0 109 reportCompare(expect, actual, status);
michael@0 110
michael@0 111
michael@0 112 *
michael@0 113 * Note: 'Zabc' is the result we expect for 'abc'.replace('', 'Z').
michael@0 114 *
michael@0 115 * The string '' is supposed to be equivalent to new RegExp('') = //.
michael@0 116 * The regexp // means we should match the "empty string" conceived of
michael@0 117 * at the beginning boundary of the word, before the first character.
michael@0 118 *
michael@0 119 status = 'Section F of test';
michael@0 120 strA = cnEmptyString;
michael@0 121 actual = str.replace(strA, strB);
michael@0 122 expect = 'Zabc';
michael@0 123 reportCompare(expect, actual, status);
michael@0 124
michael@0 125 status = 'Section G of test';
michael@0 126 strA = cnEmptyString;
michael@0 127 actual = str.replace(strA, strB);
michael@0 128 expect = str.replace(new RegExp(strA), strB);
michael@0 129 reportCompare(expect, actual, status);
michael@0 130
michael@0 131 ************************* END OF INCORRECT CASES ****************************/
michael@0 132
michael@0 133
michael@0 134 ////////////////////////// OK, LET'S START OVER //////////////////////////////
michael@0 135
michael@0 136 status = 'Section 1 of test';
michael@0 137 actual = 'abc'.replace('a', 'Z');
michael@0 138 expect = 'Zbc';
michael@0 139 reportCompare(expect, actual, status);
michael@0 140
michael@0 141 status = 'Section 2 of test';
michael@0 142 actual = 'abc'.replace('b', 'Z');
michael@0 143 expect = 'aZc';
michael@0 144 reportCompare(expect, actual, status);
michael@0 145
michael@0 146 status = 'Section 3 of test';
michael@0 147 actual = 'abc'.replace(undefined, 'Z');
michael@0 148 expect = 'abc'; // String(undefined) == 'undefined'; no replacement possible
michael@0 149 reportCompare(expect, actual, status);
michael@0 150
michael@0 151 status = 'Section 4 of test';
michael@0 152 actual = 'abc'.replace(null, 'Z');
michael@0 153 expect = 'abc'; // String(null) == 'null'; no replacement possible
michael@0 154 reportCompare(expect, actual, status);
michael@0 155
michael@0 156 status = 'Section 5 of test';
michael@0 157 actual = 'abc'.replace(true, 'Z');
michael@0 158 expect = 'abc'; // String(true) == 'true'; no replacement possible
michael@0 159 reportCompare(expect, actual, status);
michael@0 160
michael@0 161 status = 'Section 6 of test';
michael@0 162 actual = 'abc'.replace(false, 'Z');
michael@0 163 expect = 'abc'; // String(false) == 'false'; no replacement possible
michael@0 164 reportCompare(expect, actual, status);
michael@0 165
michael@0 166 status = 'Section 7 of test';
michael@0 167 actual = 'aa$aa'.replace('$', 'Z');
michael@0 168 expect = 'aaZaa'; // NOT 'aa$aaZ' as in ECMA Final Draft; see above
michael@0 169 reportCompare(expect, actual, status);
michael@0 170
michael@0 171 status = 'Section 8 of test';
michael@0 172 actual = 'abc'.replace('.*', 'Z');
michael@0 173 expect = 'abc'; // not 'Z' as in EMCA Final Draft
michael@0 174 reportCompare(expect, actual, status);
michael@0 175
michael@0 176 status = 'Section 9 of test';
michael@0 177 actual = 'abc'.replace('', 'Z');
michael@0 178 expect = 'Zabc'; // Still expect 'Zabc' for this
michael@0 179 reportCompare(expect, actual, status);
michael@0 180
michael@0 181 exitFunc ('test');
michael@0 182 }

mercurial