tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

not-escaped.js (1287B)


      1 // Copyright (C) 2024 Leo Balter. All rights reserved.
      2 // This code is governed by the BSD license found in the LICENSE file.
      3 
      4 /*---
      5 esid: sec-regexp.escape
      6 description: Numbers and alphabetic characters are not escaped
      7 info: |
      8  RegExp.escape ( string )
      9 
     10  This method produces a new string in which certain characters have been escaped.
     11  These characters are: . * + ? ^ $ | ( ) [ ] { } \
     12 
     13 features: [RegExp.escape]
     14 ---*/
     15 
     16 const asciiletter = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
     17 const decimaldigits = '0123456789';
     18 
     19 assert.sameValue(RegExp.escape(''), '', 'the empty string is not escaped');
     20 
     21 asciiletter.split('').forEach(char => {
     22  assert.sameValue(RegExp.escape(`.${char}`), `\\.${char}`, `ASCII letter ${char} is not escaped`);
     23 });
     24 
     25 assert.sameValue(RegExp.escape(`.${asciiletter}`), `\\.${asciiletter}`, 'ASCII letters are not escaped');
     26 
     27 decimaldigits.split('').forEach(char => {
     28  assert.sameValue(RegExp.escape(`.${char}`), `\\.${char}`, `decimal digit ${char} is not escaped`);
     29 });
     30 
     31 assert.sameValue(RegExp.escape(`.${decimaldigits}`), `\\.${decimaldigits}`, 'decimal digits are not escaped');
     32 
     33 assert.sameValue(RegExp.escape('.a1b2c3D4E5F6'), '\\.a1b2c3D4E5F6', 'mixed string with ASCII letters and decimal digits is not escaped');
     34 
     35 reportCompare(0, 0);