Bug 273254 - [Yarr] Regex Lookbehinds differs from v8
Summary: [Yarr] Regex Lookbehinds differs from v8
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: JavaScriptCore (show other bugs)
Version: Safari Technology Preview
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Michael Saboff
URL:
Keywords: BrowserCompat, InRadar
Depends on:
Blocks:
 
Reported: 2024-04-25 10:47 PDT by Dylan Conway
Modified: 2024-05-16 08:02 PDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dylan Conway 2024-04-25 10:47:21 PDT
The following text and regex will fail to replace. Using v8 it will match and replace successfully.

```
console.log("<TData = SettingsControllerGetAllResponse>(".replace(/(?<=TData = |<)(\w+(?:Error|Response))/g, "foo"));
```

Received output:
"<TData = SettingsControllerGetAllResponse>("

Expected output:
"<TData = foo>("


This example is minified from: https://github.com/oven-sh/bun/issues/10508
Comment 1 Radar WebKit Bug Importer 2024-05-02 10:48:52 PDT
<rdar://problem/127440248>
Comment 2 Karl Dubost 2024-05-15 01:35:27 PDT
Thanks for the report. 
I can confirm the output.

string: "<TData = SettingsControllerGetAllResponse>("
then 

.replace(
   /(?<=TData = |<)(\w+(?:Error|Response))/g, 
   "foo"
   )
Comment 3 Karl Dubost 2024-05-15 01:39:54 PDT
This gives the proper result in both Firefox and Chrome.
Comment 4 Karl Dubost 2024-05-15 01:51:14 PDT
(?<=TData = |<)(\w+(?:Error|Response))>

This one is working, aka just adding ">" at the end.
Comment 5 Karl Dubost 2024-05-15 02:00:36 PDT
OK
Just adding a Z on Error is making it work.

(?<=TData = |<)(\w+(?:ErrorZ|Response))

It seems there's a minimum size required on the strings to match set to 6 characters.

We can see that with 

(?<=TData = |<)(\w+(?:Respo))  FAIL
(?<=TData = |<)(\w+(?:Respon)) PASS
Comment 7 Karl Dubost 2024-05-15 02:05:28 PDT
There is no threshold for Firefox and Chrome

This is working for example.
(?<=TData = |<)(\w+(?:R))
Comment 8 Michael Saboff 2024-05-15 09:56:18 PDT
Currently working on this bug.

This issue is not the length itself of the lookbehind, but the lookbehind length relative to the remaining expression's minimum length.
Comment 9 Michael Saboff 2024-05-15 20:43:16 PDT
Pull request: https://github.com/WebKit/WebKit/pull/28641
Comment 10 EWS 2024-05-16 08:02:11 PDT
Committed 278863@main (fafab4133900): <https://commits.webkit.org/278863@main>

Reviewed commits have been landed. Closing PR #28641 and removing active labels.