From ce217fffad10b9908906b19bfa50c78bfe516ba4 Mon Sep 17 00:00:00 2001 From: Daniel Ehrenberg Date: Wed, 5 Apr 2017 09:25:24 +0200 Subject: [PATCH] Improve invalid \c escape tests --- .../RegExp-control-escape-russian-letter.js | 57 +++++++++++++++---- 1 file changed, 46 insertions(+), 11 deletions(-) diff --git a/test/annexB/built-ins/RegExp/RegExp-control-escape-russian-letter.js b/test/annexB/built-ins/RegExp/RegExp-control-escape-russian-letter.js index 851b881433..96f19a266d 100644 --- a/test/annexB/built-ins/RegExp/RegExp-control-escape-russian-letter.js +++ b/test/annexB/built-ins/RegExp/RegExp-control-escape-russian-letter.js @@ -5,19 +5,54 @@ info: "CharacterEscape :: c ControlLetter" es5id: 15.10.2.10_A2.1_T3 es6id: B.1.4 -description: "ControlLetter :: RUSSIAN ALPHABET is incorrect" +description: > + "ControlLetter :: RUSSIAN ALPHABET is incorrect" + Instead, fall back to semantics to match literal "\\c" ---*/ -//CHECK#0410-042F -for (var alpha = 0x0410; alpha <= 0x042F; alpha++) { - var str = String.fromCharCode(alpha % 32); - var arr = (new RegExp("\\c" + String.fromCharCode(alpha))).exec(str); - assert.sameValue(arr, null, 'RUSSIAN CAPITAL ALPHABET: ' + alpha); +function* invalidControls() { + // Check upper case Cyrillic + for (var alpha = 0x0410; alpha <= 0x042F; alpha++) { + yield String.fromCharCode(alpha); + } + + // Check lower case Cyrillic + for (alpha = 0x0430; alpha <= 0x044F; alpha++) { + yield String.fromCharCode(alpha); + } + + // Check ASCII characters which are not in the extended range or syntax + // characters + for (alpha = 0x00; alpha <= 0x7F; alpha++) { + let letter = String.fromCharCode(alpha); + if (!letter.match(/[0-9A-Za-z_\$(|)\[\]\/\\^]/)) { + yield letter; + } + } + + // Check for end of string + yield ""; } -//CHECK#0430-044F -for (alpha = 0x0430; alpha <= 0x044F; alpha++) { - str = String.fromCharCode(alpha % 32); - arr = (new RegExp("\\c" + String.fromCharCode(alpha))).exec(str); - assert.sameValue(arr, null, 'russian small alphabet: ' + alpha); +for (let letter of invalidControls()) { + var source = "\\c" + letter; + var re = new RegExp(source); + + if (letter.length > 0) { + var char = letter.charCodeAt(0); + var str = String.fromCharCode(char % 32); + var arr = re.exec(str); + + if (arr !== null) { + $ERROR(`Character ${letter} unreasonably wrapped around as a control character`); + } + } + arr = re.exec(source.substring(1)) + if (arr !== null) { + $ERROR(`invalid \\c escape matched c rather than \\c when followed by ${letter}`); + } + arr = re.exec(source) + if (arr === null) { + $ERROR(`invalid \\c escape failed to match \\c when followed by ${letter}`); + } }