RegExp: Backreference in ClassRange

N

Nisse Engström

Consider the following RegExp:

/[\1]/


ECMA-262 says:

<quote (with slight modification of non-ASCII character)>

15.10.2.11 DecimalEscape

The production DecimalEscape :: DecimalIntegerLiteral
[lookahead != DecimalDigit] evaluates as follows.

1. Let i be the MV of DecimalIntegerLiteral.
2. If i is zero, return the EscapeValue consisting of a <NUL>
character (Unicode value 0000).
3. Return the EscapeValue consisting of the integer i.

...

15.10.2.19 ClassEscape

The production ClassEscape :: DecimalEscape evaluates as follows:

1. Evaluate DecimalEscape to obtain an EscapeValue E.
2. If E is not a character then throw a SyntaxError exception.
3. Let ch be E's character.
4. Return the one-element CharSet containing the character ch.

</>


a) The DecimalEscape returns a character for "\0", and an
integer for decimals 1-9, which means that the ClassEscape
should throw an exception at step 2. Is this reading
correct?

Opera does not throw an exception.

Test case:
<http://home.swipnet.se/sigsegv/opera/bugs/js-re-class-backref.html>
Result:
<http://home.swipnet.se/sigsegv/opera/bugs/js-re-class-backref.png>


b) Interestingly, the RegExp:

/[\101-\105]+/.exec ("ABCDefgh")

results in:

* "ABCD" in FireFox 1.0.3 (octal conversion), and
* "efgh" in Opera 8.01 (decimal conversion).

An exception ought be thrown as in a), oughtn't it?


--n
 
M

Michael Winter

Consider the following RegExp:

/[\1]/

[...] the ClassEscape should throw an exception [...]

With a strict implementation of ECMA-262, yes it should. However, I
doubt that any browser implementation is strict - it would break the Web.

Notice in section 2 - Conformance:

"A conforming implementation of ECMAScript is permitted to support
program and regular expression syntax not described in this
specification."

[snip]

Mike
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top