Details
-
Bug
-
Resolution: Done
-
P1: Critical
-
5.12.2
-
Tested with MSVC2017 x86 and MinGW 7.3 x86 pre-built Qt packages from online installer.
-
71cacf22b83722c9a8668b1518028fa0835fb286 (qt/qtdeclarative/5.12)
Description
Something strange going on with String type replace() function in Qt 5.12.2 (not an issue in 5.12.1).
In the attached replace-test.qml file: There is a simple function which is supposed to strip trailing zeros from decimal numbers, eg. "123.00" -> "123" or "123.40" -> "123.4" (IRL it takes the locale separator into consideration but I've simplified it for the example).
Since 5.12.2 the example code returns "1231" for the first case (though still works for the 2nd case).
What happens with "123.00" is that in text.replace(re, "$1") the $1 is null. Somehow that turns into just the "1" which becomes the result, instead of a blank string. In previous versions a blank string is returned.
There is also a commented out workaround in the example code which fixes it for 5.12.2 and maybe makes it clearer what is going on.
I thought perhaps I was using replace() incorrectly or that it is a ECMAScript issue in general... but doesn't seem so. The attached JS version (in html file) works OK (also on https://jsfiddle.net/d2xa0esp/3/ ) (AFAICT modern Firefox uses ES6 and Chrome ES7.)