Cerca nel supporto

Attenzione alle mail truffa. Mozilla non chiederà mai di chiamare o mandare messaggi a un numero di telefono o di inviare dati personali. Segnalare qualsiasi attività sospetta utilizzando l'opzione “Segnala abuso”.

Ulteriori informazioni

Questa discussione è archiviata. Inserire una nuova richiesta se occorre aiuto.

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

  • 5 risposte
  • 1 ha questo problema
  • 16 visualizzazioni
  • Ultima risposta di 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>

Modificato da cor-el il

Tutte le risposte (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";