<?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>200714</bug_id>
          
          <creation_ts>2019-08-14 07:36:27 -0700</creation_ts>
          <short_desc>String.prototype.replace truncates $&lt;number&gt; values</short_desc>
          <delta_ts>2019-08-19 01:18:27 -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 12</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>INVALID</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>matt</reporter>
          <assigned_to name="Nobody">webkit-unassigned</assigned_to>
          <cc>fpizlo</cc>
    
    <cc>matt</cc>
    
    <cc>msaboff</cc>
    
    <cc>webkit-bug-importer</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1561148</commentid>
    <comment_count>0</comment_count>
    <who name="">matt</who>
    <bug_when>2019-08-14 07:36:27 -0700</bug_when>
    <thetext># Summary

When replacing with a value that contains $&lt;number&gt;, the value is truncated of $ and first number.

# Test

var string = &quot;Get %{amount} credit&quot;;
var regex = new RegExp(`%{amount}`, &quot;g&quot;);
console.log(string.replace(regex, &quot;$100&quot;));

# Expected

&gt; Get $100 credit

# Actual

&gt; Get 00 credit</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1561150</commentid>
    <comment_count>1</comment_count>
    <who name="">matt</who>
    <bug_when>2019-08-14 07:39:08 -0700</bug_when>
    <thetext>This could be related to a non-standard feature: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n#Examples</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1561202</commentid>
    <comment_count>2</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2019-08-14 09:59:13 -0700</bug_when>
    <thetext>&lt;rdar://problem/54306164&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1562679</commentid>
    <comment_count>3</comment_count>
    <who name="">matt</who>
    <bug_when>2019-08-19 01:18:27 -0700</bug_when>
    <thetext>After further investigation, this issue looks to be caused by an old String.prototype.replace polyfill from core-js@2.0.3.

Ref: https://github.com/zloirock/core-js/blob/v2.0.3/modules/es6.regexp.replace.js</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>