Join the AMA (Ask Me Anything) with the Firefox leadership team to celebrate Firefox 20th anniversary and discuss Firefox’s future on Mozilla Connect. Mark your calendar on Thursday, November 14, 18:00 - 20:00 UTC!

Search Support

Avoid support scams. We will never ask you to call or text a phone number or share personal information. Please report suspicious activity using the “Report Abuse” option.

Learn More

Firefox version 62, string.replace does not work as expected

  • 5 respostas
  • 1 has this problem
  • 16 views
  • Last reply by yaguang

more options

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
String.replace function on Firefox version 62 ( actually the regression may introduce from version55) has wired behavior. The case like this: <pre><nowiki>// 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" </nowiki></pre> A little change on content of the string from 'abc/abc/c' to 'abc/abc', the output will append twice. <pre><nowiki>var test='abc/abc'.replace('', './resources/js/').replace('', './resources/js/'); console.log(test) ./resources/js/./resources/js/abc/abc</nowiki></pre> Or I change the replacement string to "xy" <pre><nowiki>var test='abc/abc/cc'.replace('', 'xy').replace('', 'xy'); console.log(test) // it will append twice, xyxyabc/abc/cc</nowiki></pre>

cor-el modificouno o

All Replies (5)

more options

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

more options

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

more options

Shoving code at me does not make me understand the issue.

more options

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);

more options

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";