Firefox version 62, string.replace does not work as expected
String.replace function on Firefox version 62 ( actually the regression may introduce from version55) has wired behavior.
The case like this:
// When invoke function of String.replace twice, but it seems only work once. var test='abc/abc/c'.replace('', './resources/js/').replace('', './resources/js/'); console.log(test) // it output will "./resources/js/abc/abc/c"
A little change on content of the string from 'abc/abc/c' to 'abc/abc', the output will append twice.
var test='abc/abc'.replace('', './resources/js/').replace('', './resources/js/'); console.log(test) ./resources/js/./resources/js/abc/abc
Or I change the replacement string to "xy"
var test='abc/abc/cc'.replace('', 'xy').replace('', 'xy'); console.log(test) // it will append twice, xyxyabc/abc/cc
Geändert am
Alle Antworten (5)
Firefox update to version 62.0.2 yesterday. As there are many levels of knowledge in Firefox Volunteer Support no one has yet replied so knowing your reaching Volunteers that can not make changes to Firefox or pass the info along somewhere. you can :
Reinstall, refresh to see if either of those work to fix your issue what ever that is or you can : submit suggestions for new or changed features, Feedback: https://qsurvey.mozilla.com/s3/FirefoxInput/ or https://discourse.mozilla.org/c/add-ons If you have a bug, file a bug report. https://bugzilla.mozilla.org/ Bug Writing Guidelines : https://developer.mozilla.org/en-US/docs/Mozilla/QA/Bug_writing_guidelines
I just to update the firefox version and try the expression.
ar test='abc/abc/c'.replace(, './resources/js/').replace(, './resources/js/'); console.log(test) ; ./resources/js/abc/abc/c
The problem is still there.
Best Wishes, Yaguang
Shoving code at me does not make me understand the issue.
I do not know if using '' as a string will always work.
I would personally use a RegExp replace to add the string at the start in this case.
var test='abc/abc/c'.replace(/(.+)/, './resources/js/$1'); console.log(test);
Thanks for your reply so quickly and the actually I fixed it by regular expression as you mentioned. But I found that the behavior of the function String.replace(searchvalue, newvalue) is not consistent.
When the searchvalue string is empty , it String.replace will insert the newvalue string in the begin of the origin string
The following statement works as we expected. var result = 'abc/abc/c'.replace(, './resources/js/') ;
// result will equal to "./resources/js/abc/abc/c";
but I do replace twice, it seems only it replace once. var result='abc/abc/c'.replace(, './resources/js/').replace(, './resources/js/');
// result still equals to "./resources/js/abc/abc/c";