Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-75121

ECMAScript string.replace(RegExp, backref) (regression?) issue in 5.12.2

    XMLWordPrintable

Details

    • 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.)

      Attachments

        1. replace-test.html
          0.7 kB
        2. replace-test.js
          0.5 kB
        3. replace-test.qml
          0.7 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            mpaperno Maxim Paperno
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes