-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Updates to String.prototype.replace doesn't handle $ in replacement value without capture group #471
Comments
I'll take a look |
I believe this is an issue still. I've tested with the following: var url = "https://cdnjs.cloudflare.com/ajax/libs/core-js/2.6.8/core.js";
function loadjs(file) {
var script = document.createElement("script");
script.type = "application/javascript";
script.onload=function(){
//at this tine the script is loaded
console.log("Script loaded!");
console.log(String.prototype.replace)
console.log('{price} Retail'.replace(/{price}/g, '$25.00'))
}
script.src = file;
document.body.appendChild(script);
}
loadjs(url); Safari (In the console this is confirmed to go to the right location:
|
Safari behaves differently when RegExp.prototype[Symbol.replace].call(/{price}/g, '{price} Retail', '$25.00') // Safari - 5.00 Retail
RegExp.prototype[Symbol.replace].call(/{price}/g, '{price} Retail', '$25.00') // FF, Chrome - $25.00 Retail
RegExp.prototype[Symbol.replace].call(/{price}/g, '{price} Retail', '$test') // Safari, FF, Chrome - test Retail And as I see It can be fixed by escaping |
* checks if RegExp[Symbol.replace] substitutes undefined capture groups * use wellKnownSymbol util to get symbol key for replace method * fixes REGEXP_REPLACE_SUBSTITUTES_UNDEFINED_CAPTURE conditional logic * caches Symbol.replace as constant, uses regexp literal, swaps default for guard in fix-regexp-well-known-symbol-logic
The recent updates to String.prototype.replace are causing issues when a replacement without a capture group starts with a $.
I was specifically seeing this in Safari 12 but didn't dig in on that front beyond knowing that it wasn't affecting Chrome.
Version: 2.6.1
The text was updated successfully, but these errors were encountered: