| 1 |
// Copyright (C) 2016 the V8 project authors. All rights reserved. |
| 2 |
// This code is governed by the BSD license found in the LICENSE file. |
| 3 |
/*--- |
| 4 |
esid: sec-regular-expressions-patterns |
| 5 |
description: Legacy Octal Escape Sequence |
| 6 |
info: | |
| 7 |
CharacterEscape[U] :: |
| 8 |
ControlEscape |
| 9 |
c ControlLetter |
| 10 |
0 [lookahead ∉ DecimalDigit] |
| 11 |
HexEscapeSequence |
| 12 |
RegExpUnicodeEscapeSequence[?U] |
| 13 |
[~U] LegacyOctalEscapeSequence |
| 14 |
IdentityEscape[?U] |
| 15 |
|
| 16 |
LegacyOctalEscapeSequence :: |
| 17 |
OctalDigit [lookahead ∉ OctalDigit] |
| 18 |
ZeroToThree OctalDigit [lookahead ∉ OctalDigit] |
| 19 |
FourToSeven OctalDigit |
| 20 |
ZeroToThree OctalDigit OctalDigit |
| 21 |
|
| 22 |
The production CharacterEscape :: LegacyOctalEscapeSequence evaluates by |
| 23 |
evaluating the SV of the LegacyOctalEscapeSequence and returning its |
| 24 |
character result. |
| 25 |
---*/ |
| 26 |
|
| 27 |
assert.sameValue(/\1/.exec('\x01')[0], '\x01', '\\1'); |
| 28 |
assert.sameValue(/\2/.exec('\x02')[0], '\x02', '\\2'); |
| 29 |
assert.sameValue(/\3/.exec('\x03')[0], '\x03', '\\3'); |
| 30 |
assert.sameValue(/\4/.exec('\x04')[0], '\x04', '\\4'); |
| 31 |
assert.sameValue(/\5/.exec('\x05')[0], '\x05', '\\5'); |
| 32 |
assert.sameValue(/\6/.exec('\x06')[0], '\x06', '\\6'); |
| 33 |
assert.sameValue(/\7/.exec('\x07')[0], '\x07', '\\7'); |
| 34 |
|
| 35 |
assert.sameValue(/\00/.exec('\x00')[0], '\x00', '\\00'); |
| 36 |
assert.sameValue(/\07/.exec('\x07')[0], '\x07', '\\07'); |
| 37 |
|
| 38 |
assert.sameValue(/\30/.exec('\x18')[0], '\x18', '\\30'); |
| 39 |
assert.sameValue(/\37/.exec('\x1f')[0], '\x1f', '\\37'); |
| 40 |
|
| 41 |
assert.sameValue(/\40/.exec('\x20')[0], '\x20', '\\40'); |
| 42 |
assert.sameValue(/\47/.exec('\x27')[0], '\x27', '\\47'); |
| 43 |
|
| 44 |
assert.sameValue(/\70/.exec('\x38')[0], '\x38', '\\70'); |
| 45 |
assert.sameValue(/\77/.exec('\x3f')[0], '\x3f', '\\77'); |
| 46 |
|
| 47 |
// Sequence is bounded according to the String Value |
| 48 |
assert.sameValue(/\400/.exec('\x200')[0], '\x200', '\\400'); |
| 49 |
assert.sameValue(/\470/.exec('\x270')[0], '\x270', '\\470'); |
| 50 |
assert.sameValue(/\700/.exec('\x380')[0], '\x380', '\\700'); |
| 51 |
assert.sameValue(/\770/.exec('\x3f0')[0], '\x3f0', '\\770'); |
| 52 |
|
| 53 |
assert.sameValue(/\000/.exec('\x00')[0], '\x00', '\\000'); |
| 54 |
assert.sameValue(/\007/.exec('\x07')[0], '\x07', '\\007'); |
| 55 |
assert.sameValue(/\070/.exec('\x38')[0], '\x38', '\\070'); |
| 56 |
|
| 57 |
assert.sameValue(/\300/.exec('\xc0')[0], '\xc0', '\\300'); |
| 58 |
assert.sameValue(/\307/.exec('\xc7')[0], '\xc7', '\\307'); |
| 59 |
assert.sameValue(/\370/.exec('\xf8')[0], '\xf8', '\\370'); |
| 60 |
assert.sameValue(/\377/.exec('\xff')[0], '\xff', '\\377'); |
| 61 |
|
| 62 |
// Sequence is 3 characters max, including leading zeros |
| 63 |
assert.sameValue(/\0111/.exec('\x091')[0], '\x091', '\\0111'); |
| 64 |
assert.sameValue(/\0022/.exec('\x022')[0], '\x022', '\\0022'); |
| 65 |
assert.sameValue(/\0003/.exec('\x003')[0], '\x003', '\\0003'); |
| 66 |
|
| 67 |
var match = /(.)\1/.exec('a\x01 aa'); |
| 68 |
assert.sameValue( |
| 69 |
match[0], 'aa', 'DecimalEscape takes precedence over LegacyOctalEscapeSequence' |
| 70 |
); |
| 71 |
|
| 72 |
reportCompare(0, 0); |