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)

1.9.0 Branch
x86
Linux
defect
Not set
minor

Tracking

()

VERIFIED FIXED

People

(Reporter: T.Rosenau, Assigned: mrbkap)

Details

(Keywords: verified1.9.1, Whiteboard: fixed-in-tracemonkey)

Attachments

(1 file, 1 obsolete file)

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.
Assignee: nobody → general
Component: General → JavaScript Engine
Product: Firefox → Core
QA Contact: general → general
Version: unspecified → 1.9.0 Branch
Status: UNCONFIRMED → NEW
Ever confirmed: true
Attached patch Easy fix (obsolete) — Splinter Review
I didn't see a cleaner way to do this.
Assignee: general → mrbkap
Status: NEW → ASSIGNED
Attachment #360774 - Flags: review?(brendan)
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
Attached patch patch v2Splinter Review
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 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+
Flags: wanted1.9.1?
Whiteboard: fixed-in-tracemonkey
Status: ASSIGNED → RESOLVED
Closed: 17 years ago
Resolution: --- → FIXED
v 1.9.1, 1.9.2 ecma_3/RegExp/15.10.4.1-6.js
Status: RESOLVED → VERIFIED
Flags: wanted1.9.1?
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: