| 1 |
// Copyright 2009 the Sputnik authors. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
|
| 4 |
/*--- |
| 5 |
info: "CharacterEscape :: c ControlLetter" |
| 6 |
es5id: 15.10.2.10_A2.1_T3 |
| 7 |
es6id: B.1.4 |
| 8 |
description: > |
| 9 |
"ControlLetter :: RUSSIAN ALPHABET is incorrect" |
| 10 |
Instead, fall back to semantics to match literal "\\c" |
| 11 |
features: [generators] |
| 12 |
---*/ |
| 13 |
|
| 14 |
function* invalidControls() { |
| 15 |
// Check upper case Cyrillic |
| 16 |
for (var alpha = 0x0410; alpha <= 0x042F; alpha++) { |
| 17 |
yield String.fromCharCode(alpha); |
| 18 |
} |
| 19 |
|
| 20 |
// Check lower case Cyrillic |
| 21 |
for (alpha = 0x0430; alpha <= 0x044F; alpha++) { |
| 22 |
yield String.fromCharCode(alpha); |
| 23 |
} |
| 24 |
|
| 25 |
// Check ASCII characters which are not in the extended range or syntax |
| 26 |
// characters |
| 27 |
for (alpha = 0x00; alpha <= 0x7F; alpha++) { |
| 28 |
let letter = String.fromCharCode(alpha); |
| 29 |
if (!letter.match(/[0-9A-Za-z_\$(|)\[\]\/\\^]/)) { |
| 30 |
yield letter; |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
// Check for end of string |
| 35 |
yield ""; |
| 36 |
} |
| 37 |
|
| 38 |
for (let letter of invalidControls()) { |
| 39 |
var source = "\\c" + letter; |
| 40 |
var re = new RegExp(source); |
| 41 |
|
| 42 |
if (letter.length > 0) { |
| 43 |
var char = letter.charCodeAt(0); |
| 44 |
var str = String.fromCharCode(char % 32); |
| 45 |
var arr = re.exec(str); |
| 46 |
assert.sameValue(arr, null, `Character ${letter} unreasonably wrapped around as a control character`); |
| 47 |
} |
| 48 |
arr = re.exec(source.substring(1)); |
| 49 |
assert.sameValue(arr, null, `invalid \\c escape matched c rather than \\c when followed by ${letter}`); |
| 50 |
|
| 51 |
arr = re.exec(source); |
| 52 |
assert.notSameValue(arr, null, `invalid \\c escape failed to match \\c when followed by ${letter}`); |
| 53 |
} |