js/src/tests/ecma_3/RegExp/octal-002.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.

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

mercurial