搜索 | 用户支持

防范以用户支持为名的诈骗。我们绝对不会要求您拨打电话或发送短信,及提供任何个人信息。请使用“举报滥用”选项报告涉及违规的行为。

详细了解

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

  • 5 个回答
  • 1 人有此问题
  • 16 次查看
  • 最后回复者为 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于修改

所有回复 (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";