unable to use regexp in install.js script

RESOLVED INVALID

Status

RESOLVED INVALID
16 years ago
3 years ago

People

(Reporter: bugzilla, Assigned: dveditz)

Tracking

Trunk
x86
Windows 2000

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

16 years ago
I have an install.js script inside a xpi package that have this js:
 var re = /(.*?)\.(\d+)$/;
 re.test("1.0.1.2002111900");

The script dies with the following:
Error: can't convert Error to string
Error: re.test is not a function
Source File: 
Line: 10

isn't it possible to use regexp inside a js script in a xpi package?
(Reporter)

Comment 1

16 years ago
while this works... weird!

myProductRegVersion = "1.0.1.2002111900"
var re = new String(myProductRegVersion);
re.search(/(.*?)\.(\d+)$/);

Comment 2

16 years ago
> var re = /(.*?)\.(\d+)$/;

var re = "/(.*?)\.(\d+)$/";
will probably get you more mileage.  And I agree with the error message. 
re.test is not a function.

Comment 3

16 years ago
Henrik, are you trying to compare the used mozilla version?

You can do that with this example:

const NEED_MOZ_BUILD = 2002101708;
if (buildID < NEED_MOZ_BUILD)
  foo
else bar
(Assignee)

Comment 4

16 years ago
comment 2: brush up on regular expressions. no quotes around regexp literals and
RegExp objects most definitely have a test function.

Comment 5

16 years ago
-var re = /(.*?)\.(\d+)$/;
+var re = /(.*)\.(\d+)$/;

the '?' has nothing to act on.

Comment 6

13 years ago
Thanks Henrik, you saved my day :)

The workaround is in fact: new RegExp("(.*?)\\.(\\d+)$")
This one will has a test() method and everything.

Somehow a regexp literal isn't a real regexp in install.js, just as a string literal isn't a real string. Creating them explicitely with the "new" operator works however.

Comment 7

12 years ago
Can anyone confirm that this bug is either bogus (as I suspect, in agreement with comment #5) or fixed?
(Reporter)

Comment 8

12 years ago
not a bug
Status: NEW → RESOLVED
Last Resolved: 12 years ago
Resolution: --- → INVALID
Product: Core → Core Graveyard
You need to log in before you can comment on or make changes to this bug.