Closed
Bug 476940
Opened 17 years ago
Closed 17 years ago
JavaScript: Regular Expressions with duplicate flags should cause an error
Categories
(Core :: JavaScript Engine, defect)
Tracking
()
VERIFIED
FIXED
People
(Reporter: T.Rosenau, Assigned: mrbkap)
Details
(Keywords: verified1.9.1, Whiteboard: fixed-in-tracemonkey)
Attachments
(1 file, 1 obsolete file)
|
6.52 KB,
patch
|
brendan
:
review+
|
Details | Diff | Splinter Review |
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.5) Gecko/2008121621 Ubuntu/8.04 (hardy) Firefox/3.0.5
Build Identifier: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.5) Gecko/2008121621 Ubuntu/8.04 (hardy) Firefox/3.0.5
According to the ECMA Script specification, duplicate RexExp flags must throw a Syntax Error.
For example, these are NOT supposed to work:
var foo = /bar/ii;
var baz = new RexExp('qux', 'ii');
but they do work in Firefox.
I'm not sure whether this is a good thing. But it certainly is a spec violation.
Reproducible: Always
Steps to Reproduce:
1. Enter 'javascript:alert(/.*/ii.test('foo'));' into the address bar
2. Hit Go
Actual Results:
An alert window shows that the test succeeded.
Expected Results:
The script should throw an error (cf. error console).
Here are the corresponding sections from the spec (ECMA-262 Edition 3):
> new RegExp(pattern, flags)
> [...]
> If F [= toString(flags)] contains any character other than "g",
> "i", or "m", or if it contains the same one more than once,
> then throw a SyntaxError exception.
> Regular expression literal:
> [...]
> first, the characters comprising the regular expression's RegularExpressionBody
> and RegularExpressionFlags production expansions are collected uninterpreted
> into two strings Pattern and Flags, respectively. Then the new RegExp
> constructor is called with two arguments Pattern and Flags and the result
> becomes the value of the RegularExpressionLiteral.
Updated•17 years ago
|
Assignee: nobody → general
Component: General → JavaScript Engine
Product: Firefox → Core
QA Contact: general → general
Version: unspecified → 1.9.0 Branch
Updated•17 years ago
|
Status: UNCONFIRMED → NEW
Ever confirmed: true
| Assignee | ||
Comment 1•17 years ago
|
||
I didn't see a cleaner way to do this.
Comment 2•17 years ago
|
||
Comment on attachment 360774 [details] [diff] [review]
Easy fix
First hunk cries out for a local macro.
Why do we have JSMSG_BAD_FLAG and JSMSG_BAD_REGEXP_FLAG? Unify on latter since it sites the offending flag char?
/be
| Assignee | ||
Comment 3•17 years ago
|
||
With this patch, I get:
js> /asdf/ii
typein:1: SyntaxError: invalid regular expression flag i:
typein:1: /asdf/ii
typein:1: .......^
js> RegExp("asdf", "ii")
typein:2: SyntaxError: invalid regular expression flag i
Attachment #360774 -
Attachment is obsolete: true
Attachment #360824 -
Flags: review?(brendan)
Attachment #360774 -
Flags: review?(brendan)
Comment 4•17 years ago
|
||
Comment on attachment 360824 [details] [diff] [review]
patch v2
Righteous -- one nit: BAD_FLAG is too generic, how about renaming it BAD_REGEXP_FLAG?
/be
Attachment #360824 -
Flags: review?(brendan) → review+
| Assignee | ||
Comment 5•17 years ago
|
||
Flags: wanted1.9.1?
Whiteboard: fixed-in-tracemonkey
Comment 6•17 years ago
|
||
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
Comment 7•17 years ago
|
||
Flags: in-testsuite+
Flags: in-litmus-
Comment 8•17 years ago
|
||
Keywords: fixed1.9.1
Comment 9•17 years ago
|
||
v 1.9.1, 1.9.2 ecma_3/RegExp/15.10.4.1-6.js
Status: RESOLVED → VERIFIED
Keywords: fixed1.9.1 → verified1.9.1
| Assignee | ||
Updated•10 years ago
|
Flags: wanted1.9.1?
You need to log in
before you can comment on or make changes to this bug.
Description
•