<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>273254</bug_id>
          
          <creation_ts>2024-04-25 10:47:21 -0700</creation_ts>
          <short_desc>[Yarr] Regex Lookbehinds differs from v8</short_desc>
          <delta_ts>2024-05-16 08:02:13 -0700</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>JavaScriptCore</component>
          <version>Safari Technology Preview</version>
          <rep_platform>Unspecified</rep_platform>
          <op_sys>Unspecified</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          <see_also>https://bugs.webkit.org/show_bug.cgi?id=174931</see_also>
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>BrowserCompat, InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Dylan Conway">dylan.conway567</reporter>
          <assigned_to name="Michael Saboff">msaboff</assigned_to>
          <cc>karlcow</cc>
    
    <cc>mark.lam</cc>
    
    <cc>mike</cc>
    
    <cc>msaboff</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>ysuzuki</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>2031207</commentid>
    <comment_count>0</comment_count>
    <who name="Dylan Conway">dylan.conway567</who>
    <bug_when>2024-04-25 10:47:21 -0700</bug_when>
    <thetext>The following text and regex will fail to replace. Using v8 it will match and replace successfully.

```
console.log(&quot;&lt;TData = SettingsControllerGetAllResponse&gt;(&quot;.replace(/(?&lt;=TData = |&lt;)(\w+(?:Error|Response))/g, &quot;foo&quot;));
```

Received output:
&quot;&lt;TData = SettingsControllerGetAllResponse&gt;(&quot;

Expected output:
&quot;&lt;TData = foo&gt;(&quot;


This example is minified from: https://github.com/oven-sh/bun/issues/10508</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2032825</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2024-05-02 10:48:52 -0700</bug_when>
    <thetext>&lt;rdar://problem/127440248&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2035498</commentid>
    <comment_count>2</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2024-05-15 01:35:27 -0700</bug_when>
    <thetext>Thanks for the report. 
I can confirm the output.

string: &quot;&lt;TData = SettingsControllerGetAllResponse&gt;(&quot;
then 

.replace(
   /(?&lt;=TData = |&lt;)(\w+(?:Error|Response))/g, 
   &quot;foo&quot;
   )</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2035499</commentid>
    <comment_count>3</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2024-05-15 01:39:54 -0700</bug_when>
    <thetext>This gives the proper result in both Firefox and Chrome.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2035501</commentid>
    <comment_count>4</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2024-05-15 01:51:14 -0700</bug_when>
    <thetext>(?&lt;=TData = |&lt;)(\w+(?:Error|Response))&gt;

This one is working, aka just adding &quot;&gt;&quot; at the end.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2035504</commentid>
    <comment_count>5</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2024-05-15 02:00:36 -0700</bug_when>
    <thetext>OK
Just adding a Z on Error is making it work.

(?&lt;=TData = |&lt;)(\w+(?:ErrorZ|Response))

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

We can see that with 

(?&lt;=TData = |&lt;)(\w+(?:Respo))  FAIL
(?&lt;=TData = |&lt;)(\w+(?:Respon)) PASS</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2035505</commentid>
    <comment_count>6</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2024-05-15 02:02:42 -0700</bug_when>
    <thetext>This?
        const size_t thresholdForBinarySearch = 6;


https://searchfox.org/wubkat/rev/7051b8f5cd90af80f03a58d74741cdb04c800b6e/Source/JavaScriptCore/yarr/YarrInterpreter.cpp#520</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2035506</commentid>
    <comment_count>7</comment_count>
    <who name="Karl Dubost">karlcow</who>
    <bug_when>2024-05-15 02:05:28 -0700</bug_when>
    <thetext>There is no threshold for Firefox and Chrome

This is working for example.
(?&lt;=TData = |&lt;)(\w+(?:R))</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2035571</commentid>
    <comment_count>8</comment_count>
    <who name="Michael Saboff">msaboff</who>
    <bug_when>2024-05-15 09:56:18 -0700</bug_when>
    <thetext>Currently working on this bug.

This issue is not the length itself of the lookbehind, but the lookbehind length relative to the remaining expression&apos;s minimum length.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2035685</commentid>
    <comment_count>9</comment_count>
    <who name="Michael Saboff">msaboff</who>
    <bug_when>2024-05-15 20:43:16 -0700</bug_when>
    <thetext>Pull request: https://github.com/WebKit/WebKit/pull/28641</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>2035795</commentid>
    <comment_count>10</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2024-05-16 08:02:11 -0700</bug_when>
    <thetext>Committed 278863@main (fafab4133900): &lt;https://commits.webkit.org/278863@main&gt;

Reviewed commits have been landed. Closing PR #28641 and removing active labels.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>