Closed Bug 616798 Opened 14 years ago Closed 14 years ago

string.test global will produce unpredictable result

Categories

(Core :: XPCOM, defect)

x86
Windows Vista
defect
Not set
minor

Tracking

()

RESOLVED DUPLICATE of bug 98409

People

(Reporter: roel.strauven, Unassigned)

References

()

Details

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; nl; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ( .NET CLR 3.5.30729) Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 6.0; nl; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12 ( .NET CLR 3.5.30729) You can reproduce this by a bookmarklet: Error: javascript:var url="Rsolution.be";var i=0; while(i<5){ alert((/[[a-zA-Z_0-9]*\.\/?]*/gi).test(url)); i++;} Workaround: Without the "global" switch(/g), the result is as predicted: javascript:var url="Rsolution.be";var i=0; while(i<5){ alert((/[[a-zA-Z_0-9]*\.\/?]*/i).test(url)); i++;} Reproducible: Always Steps to Reproduce: 1. In firefox, put this in the address bar 2. javascript:var url="Rsolution.be";var i=0; while(i<5){ alert((/[[a-zA-Z_0-9]*\.\/?]*/gi).test(url)); i++;} 3. The result will switch from true to false Actual Results: true false true false true Expected Results: true true true true true If more info is needed you can contact me @ roel.strauven@rsolution.be
The 1.9.2 behavior is what the ECMAScript 3rd edition spec called for. This has since been changed in 5th edition, because it was widely agreed to be confusing (though quite predictable, if you read the spec). ;) Gecko 2.0 will have the 5th edition behavior.
Status: UNCONFIRMED → RESOLVED
Closed: 14 years ago
Resolution: --- → DUPLICATE
Component: String → XPCOM
You need to log in before you can comment on or make changes to this bug.