Bug 23121

Summary: RegExp fails for non-greedy quatifier following negative char sets w/ single char
Product: WebKit Reporter: Prestaul <webkit.prestaul>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: RESOLVED CONFIGURATION CHANGED    
Severity: Normal CC: ashvayka
Priority: P2 Keywords: HasReduction, InRadar
Version: 525.x (Safari 3.2)   
Hardware: PC   
OS: Windows XP   

Prestaul
Reported 2009-01-05 11:51:10 PST
RegExp fails to properly match strings when the pattern includes a non-greedy quantifier for a negative character class that only contains one character. For example: 'FAILURE'.replace(/^[^Z]*?$/g, 'SUCCESS'); // output: "FAILURE" 'FAILURE'.replace(/^[^Z]+?$/g, 'SUCCESS'); // output: "FAILURE" The greedy quantifier works: 'FAILURE'.replace(/^[^Z]*$/g, 'SUCCESS'); // output: "SUCCESS" More that one character works: 'FAILURE'.replace(/^[^ZQ]*?$/g, 'SUCCESS'); // output: "SUCCESS" Shorthand character classes work: 'FAILURE'.replace(/^[^\s]*?$/g, 'SUCCESS'); // output: "SUCCESS" 'FAILURE'.replace(/^[^\W]*?$/g, 'SUCCESS'); // output: "SUCCESS" Positive character classes work: 'FAILURE'.replace(/^[FAILURE]*?$/g, 'SUCCESS'); // output: "SUCCESS" 'FAILURE'.replace(/^[\w]*?$/g, 'SUCCESS'); // output: "SUCCESS" I've seen the bug on both Max and PC.
Attachments
Mark Rowe (bdash)
Comment 1 2009-01-05 15:48:57 PST
Alexey Shvayka
Comment 2 2020-02-06 12:25:11 PST
(In reply to Prestaul from comment #0) > RegExp fails to properly match strings when the pattern includes a > non-greedy quantifier for a negative character class that only contains one > character. For example: > > 'FAILURE'.replace(/^[^Z]*?$/g, 'SUCCESS'); // output: "FAILURE" > 'FAILURE'.replace(/^[^Z]+?$/g, 'SUCCESS'); // output: "FAILURE" As of rev. 255785, both test cases output "SUCCESS". Test coverage: https://trac.webkit.org/browser/webkit/trunk/LayoutTests/fast/regex/script-tests/pcre-test-1.js?rev=255785#L2753
Note You need to log in before you can comment on or make changes to this bug.