Bug 200714
| Summary: | String.prototype.replace truncates $<number> values | ||
|---|---|---|---|
| Product: | WebKit | Reporter: | matt |
| Component: | JavaScriptCore | Assignee: | Nobody <webkit-unassigned> |
| Status: | RESOLVED INVALID | ||
| Severity: | Normal | CC: | fpizlo, matt, msaboff, webkit-bug-importer |
| Priority: | P2 | Keywords: | InRadar |
| Version: | Safari 12 | ||
| Hardware: | All | ||
| OS: | All | ||
matt
# Summary
When replacing with a value that contains $<number>, the value is truncated of $ and first number.
# Test
var string = "Get %{amount} credit";
var regex = new RegExp(`%{amount}`, "g");
console.log(string.replace(regex, "$100"));
# Expected
> Get $100 credit
# Actual
> Get 00 credit
| Attachments | ||
|---|---|---|
| Add attachment proposed patch, testcase, etc. |
matt
This could be related to a non-standard feature: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/n#Examples
Radar WebKit Bug Importer
<rdar://problem/54306164>
matt
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