Closed
Bug 248444
Opened 20 years ago
Closed 20 years ago
toString/toSource of RegExp does not escape slashes
Categories
(Core :: JavaScript Engine, defect, P3)
Core
JavaScript Engine
Tracking
()
VERIFIED
FIXED
mozilla1.8alpha2
People
(Reporter: timeless, Assigned: shaver)
References
()
Details
(Keywords: fixed-aviary1.0, fixed1.7, js1.5)
Attachments
(2 files, 1 obsolete file)
3.50 KB,
patch
|
shaver
:
review+
brendan
:
approval1.7.5+
|
Details | Diff | Splinter Review |
2.70 KB,
text/plain
|
Details |
js> eval(""+RegExp("[^/]+$"))
typein:1: SyntaxError: unterminated character class ^:
typein:1: /[^/]+$/
typein:1: ^
js> build()
built on Jun 21 2004 at 18:03:35
(boffo)
also tested: mozilla1.4.1 (viper), mozilla1.2.1 (boffo), 1.7b (lab-xp-tp1)
afaik RegExp("[^/]+$") should be approximately equivalent to /[^\/]+$/
The testing example I have is:
"somepath/file.ext".match(regexpobject)[0]
expected output is: "file.ext".
since I'm using the regular expression twice, I figured I'd construct and store
the object instead of inlining it. Since I'm not particularly fond of escaping
things, I decided to use the RegExp() form. The form works, but xpcshell/js and
venkman all showed sketchy string representations. Note that the non RegExp
constructor /[^\/]+$/ form does correctly unescape.
The nature of the error message for my testcase will vary depending on whether
the build you're using is from before or after the regexp landing (e.g. 1.2.1
output):
js> eval(""+RegExp("[^/]+$"))
typein:1: SyntaxError: unterminated character class [:
typein:1: /[^/]+$/
typein:1: ^
js> build()
built on Nov 30 2002 at 14:36:14
Things to test:
/[^\/]+$/
RegExp("[^\\\/]+$")
RegExp("[^\\/]+$")
RegExp("[^\/]+$")
RegExp("[^/]+$")
Personally, I expect all of the preceding to behave the same (both as regular
expressions and as things convertable to strings).
Summary: Unescape of character class [^/] is broken → Unescape of character class [^/] constructed with RegExp constructor is broken
Assignee | ||
Comment 1•20 years ago
|
||
Ah, sweet RegExp. I think we're up to about 800 cuts now.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Updated•20 years ago
|
Keywords: js1.5
OS: Windows XP → All
Priority: -- → P3
Hardware: PC → All
Target Milestone: --- → mozilla1.8alpha2
Assignee | ||
Comment 3•20 years ago
|
||
It's true that the toString/toSource representation isn't lot of use as
eval-fodder, but IE(6) does the same thing, so I'm not sure we can change
toString. Maybe toSource? Teetering towards WONTFIX.
Note that the RegExp(RegExp("/").source) works, though.
Assignee: general → shaver
Summary: Unescape of character class [^/] constructed with RegExp constructor is broken → toString/toSource of RegExp does not escape slashes
Assignee | ||
Comment 4•20 years ago
|
||
Not js1.5 -- breaking compat isn't a release requirement, usually.
(Wonder what 4.x does.)
Status: NEW → ASSIGNED
Keywords: js1.5
Mozilla/4.8 [en] (Windows NT 5.0; U): (RegExp("/")).toSource() => ///
Mozilla/4.8 [en] (Windows NT 5.0; U): (RegExp("/")).toString() => ///
Comment 6•20 years ago
|
||
Per ECMA-262 Edition 3, 15.10.6.4.
/be
Updated•20 years ago
|
Attachment #152453 -
Flags: review?(shaver)
Comment 7•20 years ago
|
||
See the NOTE in 15.10.6.4 -- it allows "///" to be the result of
RegExp("/").toString(). The spec also allows what the patch here does, which
seems better enough to be worth doing.
/be
Assignee | ||
Comment 8•20 years ago
|
||
Comment on attachment 152453 [details] [diff] [review]
proposed fix
Seems kinda a shame that we have this match_or_replace thing that can do _one_
text replacement for us, but not a global string replacement. Still...
Attachment #152453 -
Flags: review?(shaver) → review+
Comment 9•20 years ago
|
||
match_or_replace can work globally. However, calling it from the engine to
replace / with \/ is tricky: you need a regexp with a negative lookbehind
asserting that \ does not precede / (either / is at the front of the string, or
there's no \ char before the /). Seems better to open-code it (and not to worry
about avoiding reallocs).
/be
Comment 10•20 years ago
|
||
Oops -- first patch sucked, forgot to scale length by sizeof(jschar).
/be
Updated•20 years ago
|
Attachment #152477 -
Flags: review?(shaver)
Updated•20 years ago
|
Attachment #152453 -
Attachment is obsolete: true
Attachment #152453 -
Flags: review+
Assignee | ||
Comment 11•20 years ago
|
||
Comment on attachment 152477 [details] [diff] [review]
proposed fix, v2
Even better. r=shaver
Attachment #152477 -
Flags: review?(shaver) → review+
Comment 12•20 years ago
|
||
Fixed.
/be
Status: ASSIGNED → RESOLVED
Closed: 20 years ago
Resolution: --- → FIXED
Attachment #152477 -
Flags: approval1.7.1?
Attachment #152477 -
Flags: approval1.4.3?
Comment 13•20 years ago
|
||
1.4.3? Whatever.
Timeless, you can do the work. I actually would rather *not* make this change
in any branch, since we were ECMA-conformant, and backward compatible, till this
went in for 1.8a2. What's your requirement, exactly?
/be
Comment 14•20 years ago
|
||
Would like to sync up aviary 1.0 with current trunk in this regard.
/be
Flags: blocking-aviary1.0+
Reporter | ||
Comment 15•20 years ago
|
||
i'm not likely to use 1.4.3, but i am likely to use 1.7.x. I'm fine with not
doing 1.4.3.
Flags: blocking1.7.1?
Comment 16•20 years ago
|
||
I am against this landing on the 1.4 branch.
Attachment #152477 -
Flags: approval1.4.3?
Comment 17•20 years ago
|
||
Comment on attachment 152477 [details] [diff] [review]
proposed fix, v2
Per drivers' edict that 1.7x and aviary1.0 back-end modules match, I'm plusing
for 1.7.3.
/be
Attachment #152477 -
Flags: approval1.7.3? → approval1.7.3+
Updated•20 years ago
|
Flags: blocking1.7.5?
Comment 19•20 years ago
|
||
thanks to timeless.
Comment 20•20 years ago
|
||
js1_5/Regress/regress-248444.js checked in.
Updated•19 years ago
|
Flags: testcase+
You need to log in
before you can comment on or make changes to this bug.
Description
•