| 1 |
// |reftest| shell-option(--enable-regexp-escape) skip-if(!RegExp.escape||!xulRuntime.shell) -- RegExp.escape is not enabled unconditionally, requires shell-options |
| 2 |
// Copyright (C) 2024 Leo Balter, Jordan Harband. All rights reserved. |
| 3 |
// This code is governed by the BSD license found in the LICENSE file. |
| 4 |
|
| 5 |
/*--- |
| 6 |
esid: sec-encodeforregexescape |
| 7 |
description: UTF16EncodeCodePoint is called for remaining codepoints |
| 8 |
info: | |
| 9 |
EncodeForRegExpEscape ( c ) |
| 10 |
|
| 11 |
3. Let otherPunctuators be the string-concatenation of ",-=<>#&!%:;@~'`" and the code unit 0x0022 (QUOTATION MARK). |
| 12 |
4. Let toEscape be StringToCodePoints(otherPunctuators). |
| 13 |
5. If toEscape contains c, c is matched by WhiteSpace or LineTerminator, or c has the same numeric value as a leading surrogate or trailing surrogate, then |
| 14 |
... |
| 15 |
6. Return UTF16EncodeCodePoint(c). |
| 16 |
features: [RegExp.escape] |
| 17 |
---*/ |
| 18 |
|
| 19 |
const codePoints = String.fromCharCode(0x100, 0x200, 0x300); |
| 20 |
|
| 21 |
assert.sameValue(RegExp.escape(codePoints), codePoints, 'characters are correctly not escaped'); |
| 22 |
|
| 23 |
assert.sameValue(RegExp.escape('你好'), '你好', 'Chinese characters are correctly not escaped'); |
| 24 |
assert.sameValue(RegExp.escape('こんにちは'), 'こんにちは', 'Japanese characters are correctly not escaped'); |
| 25 |
assert.sameValue(RegExp.escape('안녕하세요'), '안녕하세요', 'Korean characters are correctly not escaped'); |
| 26 |
assert.sameValue(RegExp.escape('Привет'), 'Привет', 'Cyrillic characters are correctly not escaped'); |
| 27 |
assert.sameValue(RegExp.escape('مرحبا'), 'مرحبا', 'Arabic characters are correctly not escaped'); |
| 28 |
assert.sameValue(RegExp.escape('हेलो'), 'हेलो', 'Devanagari characters are correctly not escaped'); |
| 29 |
assert.sameValue(RegExp.escape('Γειά σου'), 'Γειά\\x20σου', 'Greek characters are correctly not escaped'); |
| 30 |
assert.sameValue(RegExp.escape('שלום'), 'שלום', 'Hebrew characters are correctly not escaped'); |
| 31 |
assert.sameValue(RegExp.escape('สวัสดี'), 'สวัสดี', 'Thai characters are correctly not escaped'); |
| 32 |
assert.sameValue(RegExp.escape('नमस्ते'), 'नमस्ते', 'Hindi characters are correctly not escaped'); |
| 33 |
assert.sameValue(RegExp.escape('ሰላም'), 'ሰላም', 'Amharic characters are correctly not escaped'); |
| 34 |
assert.sameValue(RegExp.escape('हैलो'), 'हैलो', 'Hindi characters with diacritics are correctly not escaped'); |
| 35 |
assert.sameValue(RegExp.escape('안녕!'), '안녕\\x21', 'Korean character with special character is correctly escaped'); |
| 36 |
assert.sameValue(RegExp.escape('.hello\uD7FFworld'), '\\.hello\uD7FFworld', 'Mixed ASCII and Unicode characters are correctly escaped'); |
| 37 |
|
| 38 |
reportCompare(0, 0); |