Closed Bug 1727109 Opened 4 years ago Closed 4 years ago

regular expression

Categories

(DevTools :: Console, defect, P2)

Firefox 91
defect

Tracking

(Not tracked)

RESOLVED DUPLICATE of bug 1609429

People

(Reporter: telescop603, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.159 Safari/537.36

Steps to reproduce:

Good evening!

I created a regular expression with a sticky flag (should match any non-digit symbol):
let reg = /\D+/y
Then assigned it lastIndex:
reg.lastIndex = 6
And tested with this expression
reg.test('333333D')

Actual results:

It shows false

Expected results:

The result must be true because index 6 is a letter. I've tested this in Chrome and got true.

Component: Untriaged → JavaScript Engine
Product: Firefox → Core

This is only an issue when executing the steps in the devtools console, because the expression evaluation preview executes reg.test('333333D'), but doesn't reset reg.lastIndex. If you type reg.test('333333D') without pressing the enter-key, the preview will show the value true. When the enter-key is then pressed, the regular expression is executed another time and the result false is returned. When all steps are enclosed in a block-statement, the correct result true is returned:

{ let reg = /\D+/y; reg.lastIndex = 6; reg.test('333333D') }
Component: JavaScript Engine → Console
Product: Core → DevTools

Nicolas: probably should flag this expression as having side effects? Can you point to where this is handled.

Severity: -- → S3
Status: UNCONFIRMED → NEW
Ever confirmed: true
Flags: needinfo?(nchevobbe)
Priority: -- → P2

This is a known issue (see Bug 1609429)
I'm going to mark this bug as a duplicate, and we should probably disabled instant evaluation for regex as we already have bug reports about it.

Status: NEW → RESOLVED
Closed: 4 years ago
Flags: needinfo?(nchevobbe)
Resolution: --- → DUPLICATE

(In reply to André Bargull [:anba] from comment #1)

This is only an issue when executing the steps in the devtools console, because the expression evaluation preview executes reg.test('333333D'), but doesn't reset reg.lastIndex. If you type reg.test('333333D') without pressing the enter-key, the preview will show the value true. When the enter-key is then pressed, the regular expression is executed another time and the result false is returned. When all steps are enclosed in a block-statement, the correct result true is returned:

{ let reg = /\D+/y; reg.lastIndex = 6; reg.test('333333D') }

Huge thanks for the great explanation! Now I understand why it works like this.

You need to log in before you can comment on or make changes to this bug.