not-escaped-underscore.js (1659B)
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-encodeforregexescape 6 description: Ensures the underscore character is 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: . * + ? ^ $ | ( ) [ ] { } \ , - = < > # & ! % : ; @ ~ ' ` " and white space or line terminators. 12 features: [RegExp.escape] 13 ---*/ 14 15 assert.sameValue(RegExp.escape('_'), '_', 'Single underscore character is not escaped'); 16 assert.sameValue(RegExp.escape('__'), '__', 'Thunderscore character is not escaped'); 17 assert.sameValue(RegExp.escape('hello_world'), '\\x68ello_world', 'String starting with ASCII letter and containing underscore is correctly escaped'); 18 assert.sameValue(RegExp.escape('1_hello_world'), '\\x31_hello_world', 'String starting with digit and containing underscore is correctly escaped'); 19 assert.sameValue(RegExp.escape('a_b_c'), '\\x61_b_c', 'String starting with ASCII letter and containing multiple underscores is correctly escaped'); 20 assert.sameValue(RegExp.escape('3_b_4'), '\\x33_b_4', 'String starting with digit and containing multiple underscores is correctly escaped'); 21 assert.sameValue(RegExp.escape('_hello'), '_hello', 'String starting with underscore and containing other characters is not escaped'); 22 assert.sameValue(RegExp.escape('_1hello'), '_1hello', 'String starting with underscore and digit is not escaped'); 23 assert.sameValue(RegExp.escape('_a_1_2'), '_a_1_2', 'String starting with underscore and mixed characters is not escaped'); 24 25 reportCompare(0, 0);