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!

Mozilla 도움말 검색

고객 지원 사기를 피하세요. 저희는 여러분께 절대로 전화를 걸거나 문자를 보내거나 개인 정보를 공유하도록 요청하지 않습니다. "악용 사례 신고"옵션을 사용하여 의심스러운 활동을 신고해 주세요.

자세히 살펴보기

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