hermes icon indicating copy to clipboard operation
hermes copied to clipboard

Regex bug

Open Georgezxh opened this issue 2 years ago • 7 comments

Bug Description

Hermes version: 0.12.0 OS version (if any): ubuntu 20.04 Hi. The code below does not have the same behavior as other engines (e.g., V8 in Google Chrome,SpiderMonkey in Firefox,chakra in Edge,quickjs,jerryscript). This test case works correctly in other js engines with returning a matched result, but in hermes return null.

Steps To Reproduce

1.var regex=/((?:(?:|[A-Z])((?:n*.)){1}))+(?:\2\2*)/; 2.regex.exec("NnnX")

image

The Expected Behavior

[ "Nnn", "n", "n" ]

image

Georgezxh avatar Jan 19 '23 07:01 Georgezxh

Hi,

Thank you for your feedback. We are taking a look at the issue.

John Paul

jpporto avatar Jan 20 '23 17:01 jpporto

Hi, is this confirmed to be a bug?

Georgezxh avatar Mar 29 '23 11:03 Georgezxh

Yes, I have confirmed that Hermes is not outputting the same as other engines. I have also reduced the repro to the following:

var p = typeof(globalThis.print) === "undefined" ? globalThis.console.log : globalThis.print;
var regex=/^((n*.){1})+\1/;
p(regex.exec("nn"));

Running this in Hermes prints null, but outputs a match in V8.

fbmal7 avatar Mar 30 '23 19:03 fbmal7

Thanks a lot! I tried this repro and it did print null. However I want to confirm whether https://github.com/facebook/hermes/issues/950 really a duplicate of this, because though the regex of them are the same, the behaviors are not. This matches nothing and prints null but https://github.com/facebook/hermes/issues/950 returns a wrong matched result.

Georgezxh avatar Mar 31 '23 07:03 Georgezxh

Yes they are coming from the same bug. This regex is different so it's expected that the end result would be different. The trigger of the bug seems to be {1} quantifier. In both issues you opened, and in the repro I provided, removing the {1} in the regex makes Hermes output the correct match.

fbmal7 avatar Mar 31 '23 16:03 fbmal7

Yes they are coming from the same bug. This regex is different so it's expected that the end result would be different. The trigger of the bug seems to be {1} quantifier. In both issues you opened, and in the repro I provided, removing the {1} in the regex makes Hermes output the correct match.

Fine, thanks.

Georgezxh avatar Mar 31 '23 17:03 Georgezxh

Confirmed, the bug still exists.

tmikov avatar Oct 18 '24 17:10 tmikov