Closed
Bug 105972
Opened 23 years ago
Closed 23 years ago
/^.*?$/ will not match anything
Categories
(Core :: JavaScript Engine, defect)
Core
JavaScript Engine
Tracking
()
VERIFIED
FIXED
mozilla0.9.8
People
(Reporter: mozilla, Assigned: rogerl)
Details
(Whiteboard: [In Rhino, this is bug 106548])
Attachments
(2 files)
301 bytes,
patch
|
brendan
:
review+
brendan
:
superreview+
|
Details | Diff | Splinter Review |
1.22 KB,
patch
|
khanson
:
review+
brendan
:
superreview+
|
Details | Diff | Splinter Review |
The result of the following example:
/^.*?$/.exec("hello world")[0]
is an empty string. If I understand correctly, the *? construct should match the
minimum number of characters required to make a complete match, which means it should
match the entire string "hello world".
On the other hand,
/^.*$/.exec("hello world")[0]
/^.+?$/.exec("hello world")[0]
/^.*?d/.exec("hello world")[0]
all return the string "hello world".
Perhaps I am simply misinterpreting the spec, in which case I'm sorry for wasting your
time. But it seems that it would be more logical that /^.*?$/ should work. I have not
had a chance to test this with other JS interpreters.
Comment 1•23 years ago
|
||
Reassigning to rogerl. Same behavior in the SpiderMonkey shell:
js> /^.*?$/.exec("Hello World") === null
true
By contrast, Perl 5 matches the whole string. This script:
if ("Hello World" =~ /^.*?$/)
{
print("match: $&\n");
}
else
{
print("NO MATCH!\n");
}
produces this output:
match: Hello World
Assignee: nboyd → rogerl
OS: Linux → All
Hardware: PC → All
Whiteboard: [SpiderMonkey has the same problem]
Comment 2•23 years ago
|
||
Testcase added to JS testsuite:
mozilla/js/tests/ecma_3/RegExp/regress-105972.js
Assignee | ||
Comment 3•23 years ago
|
||
Assignee | ||
Updated•23 years ago
|
Status: NEW → ASSIGNED
Reporter | ||
Comment 4•23 years ago
|
||
Thanks rogerl for the quick turnaround! As part of the reason for filing this bug,
though, I want to verify that more complicated cases work with your fix, such as:
/^.*?(:|$)/.exec("hello: world") => "hello:"
/^.*?(:|$)/.exec("hello: world") => "hello world"
(I do not have a source build available to test your patch myself). Thank you!
Assignee | ||
Comment 5•23 years ago
|
||
I'm guessing the second example was supposed to be
/^.*(:|$)/.exec("hello: world")
(i.e. greedy)
That being the case the results are:
/^.*?(:|$)/.exec("hello: world") => hello:,:
/^.*(:|$)/.exec("hello: world") => hello: world,
as expected. I think.
Comment 6•23 years ago
|
||
The latter two examples have been added to the testcase above.
Both of them already pass in SpiderMonkey and Rhino, without the
patch to this bug even being applied.
For example, in SpiderMonkey, using the toSource() operator
to display the match arrays:
------------- NON-GREEDY CASE (*? operator) -------------
js> /^.*?(:|$)/.exec("Hello: World").toSource()
["Hello:", ":"]
------------- GREEDY CASE (* operator) ------------------
js> /^.*(:|$)/.exec("Hello: World").toSource()
["Hello: World", ""]
Reporter | ||
Comment 7•23 years ago
|
||
> I'm guessing the second example was supposed to be
> /^.*(:|$)/.exec("hello: world")
Sorry, the example was supposed to be:
/^.*?(:|$)/.exec("hello world")
Comment 8•23 years ago
|
||
This must be the SpiderMonkey bug if that's what the patch fixes -- or should a
twin bug be filed on the JavaScript Engine component of the Browser product?
/be
Comment 9•23 years ago
|
||
Changing product/component from Rhino/Core to Browser/JS Engine.
I have filed bug 106548 as the twin bug against Rhino -
Component: Core → Javascript Engine
Product: Rhino → Browser
Updated•23 years ago
|
Whiteboard: [SpiderMonkey has the same problem] → [In Rhino, this is bug 106548]
Comment 10•23 years ago
|
||
cc'ing some more reviewers for this patch -
Comment 11•23 years ago
|
||
r=khanson
Comment 12•23 years ago
|
||
Comment on attachment 54703 [details] [diff] [review]
Allow non-greedy matching up to AND including cpend to match EOL
diff -u format please (you should be able to set that as a default cvs diff
option, via .cvsrc or a MacCVS option [I hope!]).
The only worry I had was that the loop body (not shown due to lack of diff -u
context) would load *cp2 when cp2 == cpend, but that seems to be impossible
from a quick glance at matchRENodes and the REOP_EOL case. Maybe JS_ASSERT
before the if (*cp2 == '\n') test that cp2 < cpend, just to be sure?
sr=brendan@mozilla.org with whatever assertion makes sense.
I'm recording khanson's r= via the patch manager (kenton, please get in the
habit of doing that, it helps mozilla.org gather stats -- thanks).
/be
Attachment #54703 -
Flags: superreview+
Attachment #54703 -
Flags: review+
Assignee | ||
Comment 13•23 years ago
|
||
Brendan's right about loading *cp2 from cpend. If the next node does fail to
match, we would merrily attempt to look for a line terminator, eventually from
beyond the end of string. New patch (with context) detects that attempt and
fails.
Comment 14•23 years ago
|
||
Comment on attachment 62050 [details] [diff] [review]
Correct overrun error from previous patch
I think this is good to go now. Does it need re-review from khanson?
/be
Attachment #62050 -
Flags: superreview+
Comment 15•23 years ago
|
||
Yes, I will re review.
=Kenton=
Comment 16•23 years ago
|
||
Comment on attachment 62050 [details] [diff] [review]
Correct overrun error from previous patch
r=khanson
Attachment #62050 -
Flags: review+
Comment 17•23 years ago
|
||
Wahh, another patch all reviewed and ready to go, but not checked in. Please
set target milestone and check in ASAP (by midnight tonight for 0.9.8, or appeal
to drivers@mozilla.org during the 0.9.8 freeze -- else 0.9.9 or bust).
/be
Assignee | ||
Comment 18•23 years ago
|
||
Nuts, sorry - I had forgotten these were pending. Fix checked in.
Status: ASSIGNED → RESOLVED
Closed: 23 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla0.9.8
Comment 19•23 years ago
|
||
Marking Verified FIXED. The above testcase now passes in the
debug and optimized JS shell on Linux, WinNT, and Mac9.1.
Status: RESOLVED → VERIFIED
Updated•20 years ago
|
Flags: testcase+
You need to log in
before you can comment on or make changes to this bug.
Description
•