Closed
Bug 351342
Opened 19 years ago
Closed 18 years ago
Perl RegExp test 255: /((\3|b)\2(a)x)+/.exec('aaxabxbaxbbx')
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
RESOLVED
INVALID
People
(Reporter: bc, Unassigned)
References
()
Details
expected null (MSIE6 agrees)
actual ax,ax,,a
Comment 1•18 years ago
|
||
Why would you expect null?
The \3 matches the empty string, since by that point it hasn't yet matched anything. The \2 then matches the empty string because the second set of brackets matched nothing (it matched nothing, at the start of the test string). So we get to (a), which matches the first character, but we have to backtrack because the "x" doesn't match on the second character. So the \3 matches the empty string between the two "a"s, the \2 matches the same empty string, the (a) matches the second "a", and then the last "x" matches the third character. At this point \1 is complete, it matched the "ax".
I think this is invalid.
Comment 2•18 years ago
|
||
Here's what perl's regexp debug mode says:
Compiling REx `((\3|b)\2(a)x)+'
size 29 Got 236 bytes for offset annotations.
first at 7
1: CURLYX[0] {1,32767}(28)
3: OPEN1(5)
5: OPEN2(7)
7: BRANCH(10)
8: REF3(13)
10: BRANCH(13)
11: EXACT <b>(13)
13: CLOSE2(15)
15: REF2(17)
17: OPEN3(19)
19: EXACT <a>(21)
21: CLOSE3(23)
23: EXACT <x>(25)
25: CLOSE1(27)
27: WHILEM[1/1](0)
28: NOTHING(29)
29: END(0)
floating "ax" at 0..2147483647 (checking floating) minlen 2
Offsets: [29]
15[1] 0[0] 1[1] 0[0] 2[1] 0[0] 2[1] 3[2] 0[0] 5[1] 6[1] 0[0] 7[1] 0[0] 8[2] 0[0] 10[1] 0[0] 11[1] 0[0] 12[1] 0[0] 13[1] 0[0] 14[1] 0[0] 15[0] 15[0] 16[0]
Guessing start of match, REx "((\3|b)\2(a)x)+" against "aaxabxbaxbbx"...
Found floating substr "ax" at offset 1...
Guessed: match at offset 0
Matching REx "((\3|b)\2(a)x)+" against "aaxabxbaxbbx"
Setting an EVAL scope, savestack=3
0 <> <aaxabxbaxbbx> | 1: CURLYX[0] {1,32767}
0 <> <aaxabxbaxbbx> | 27: WHILEM[1/1]
0 out of 1..32767 cc=bffff454
0 <> <aaxabxbaxbbx> | 3: OPEN1
0 <> <aaxabxbaxbbx> | 5: OPEN2
0 <> <aaxabxbaxbbx> | 7: BRANCH
Setting an EVAL scope, savestack=13
0 <> <aaxabxbaxbbx> | 8: REF3
failed...
0 <> <aaxabxbaxbbx> | 11: EXACT <b>
failed...
failed...
failed...
Setting an EVAL scope, savestack=3
1 <a> <axabxbaxbbx> | 1: CURLYX[0] {1,32767}
1 <a> <axabxbaxbbx> | 27: WHILEM[1/1]
0 out of 1..32767 cc=bffff454
1 <a> <axabxbaxbbx> | 3: OPEN1
1 <a> <axabxbaxbbx> | 5: OPEN2
1 <a> <axabxbaxbbx> | 7: BRANCH
Setting an EVAL scope, savestack=13
1 <a> <axabxbaxbbx> | 8: REF3
failed...
1 <a> <axabxbaxbbx> | 11: EXACT <b>
failed...
failed...
failed...
Setting an EVAL scope, savestack=3
2 <aa> <xabxbaxbbx> | 1: CURLYX[0] {1,32767}
2 <aa> <xabxbaxbbx> | 27: WHILEM[1/1]
0 out of 1..32767 cc=bffff454
2 <aa> <xabxbaxbbx> | 3: OPEN1
2 <aa> <xabxbaxbbx> | 5: OPEN2
2 <aa> <xabxbaxbbx> | 7: BRANCH
Setting an EVAL scope, savestack=13
2 <aa> <xabxbaxbbx> | 8: REF3
failed...
2 <aa> <xabxbaxbbx> | 11: EXACT <b>
failed...
failed...
failed...
Setting an EVAL scope, savestack=3
3 <aax> <abxbaxbbx> | 1: CURLYX[0] {1,32767}
3 <aax> <abxbaxbbx> | 27: WHILEM[1/1]
0 out of 1..32767 cc=bffff454
3 <aax> <abxbaxbbx> | 3: OPEN1
3 <aax> <abxbaxbbx> | 5: OPEN2
3 <aax> <abxbaxbbx> | 7: BRANCH
Setting an EVAL scope, savestack=13
3 <aax> <abxbaxbbx> | 8: REF3
failed...
3 <aax> <abxbaxbbx> | 11: EXACT <b>
failed...
failed...
failed...
Setting an EVAL scope, savestack=3
4 <aaxa> <bxbaxbbx> | 1: CURLYX[0] {1,32767}
4 <aaxa> <bxbaxbbx> | 27: WHILEM[1/1]
0 out of 1..32767 cc=bffff454
4 <aaxa> <bxbaxbbx> | 3: OPEN1
4 <aaxa> <bxbaxbbx> | 5: OPEN2
4 <aaxa> <bxbaxbbx> | 7: BRANCH
Setting an EVAL scope, savestack=13
4 <aaxa> <bxbaxbbx> | 8: REF3
failed...
4 <aaxa> <bxbaxbbx> | 11: EXACT <b>
5 <aaxab> <xbaxbbx> | 13: CLOSE2
5 <aaxab> <xbaxbbx> | 15: REF2
failed...
failed...
failed...
Setting an EVAL scope, savestack=3
5 <aaxab> <xbaxbbx> | 1: CURLYX[0] {1,32767}
5 <aaxab> <xbaxbbx> | 27: WHILEM[1/1]
0 out of 1..32767 cc=bffff454
5 <aaxab> <xbaxbbx> | 3: OPEN1
5 <aaxab> <xbaxbbx> | 5: OPEN2
5 <aaxab> <xbaxbbx> | 7: BRANCH
Setting an EVAL scope, savestack=13
5 <aaxab> <xbaxbbx> | 8: REF3
failed...
5 <aaxab> <xbaxbbx> | 11: EXACT <b>
failed...
failed...
failed...
Setting an EVAL scope, savestack=3
6 <aaxabx> <baxbbx> | 1: CURLYX[0] {1,32767}
6 <aaxabx> <baxbbx> | 27: WHILEM[1/1]
0 out of 1..32767 cc=bffff454
6 <aaxabx> <baxbbx> | 3: OPEN1
6 <aaxabx> <baxbbx> | 5: OPEN2
6 <aaxabx> <baxbbx> | 7: BRANCH
Setting an EVAL scope, savestack=13
6 <aaxabx> <baxbbx> | 8: REF3
failed...
6 <aaxabx> <baxbbx> | 11: EXACT <b>
7 <aaxabxb> <axbbx> | 13: CLOSE2
7 <aaxabxb> <axbbx> | 15: REF2
failed...
failed...
failed...
Setting an EVAL scope, savestack=3
7 <aaxabxb> <axbbx> | 1: CURLYX[0] {1,32767}
7 <aaxabxb> <axbbx> | 27: WHILEM[1/1]
0 out of 1..32767 cc=bffff454
7 <aaxabxb> <axbbx> | 3: OPEN1
7 <aaxabxb> <axbbx> | 5: OPEN2
7 <aaxabxb> <axbbx> | 7: BRANCH
Setting an EVAL scope, savestack=13
7 <aaxabxb> <axbbx> | 8: REF3
failed...
7 <aaxabxb> <axbbx> | 11: EXACT <b>
failed...
failed...
failed...
Match failed
false
Freeing REx: `"((\\3|b)\\2(a)x)+"'
Comment 3•18 years ago
|
||
I think we fail to agree perl here due to the fact that we don't "float" a flat expression (here, "ax") at the beginning of the search, and thus haven't, as Hixie suggests, matched anything for the backreferences to chew on as they analyze the string.
I guess this is simply a matter of deciding how closely we wish to emulate perl. I think this very corner case of backreferences isn't worth pursuing. Instead, let's specific backreferences /out/ of ES4 and simplify everything. ;)
Status: NEW → RESOLVED
Closed: 18 years ago
Resolution: --- → INVALID
You need to log in
before you can comment on or make changes to this bug.
Description
•