Uploaded image for project: 'PUBLIC - Liferay Portal Community Edition'
  1. PUBLIC - Liferay Portal Community Edition
  2. LPS-24685

StringUtil.replace(..., exactMatch) does not return replacement when exactMatch=false

    Details

    • Branch Version/s:
      6.1.x
    • Backported to Branch:
      Committed

      Description

      When calling StringUtil.replace(String s, String[] oldSubs, String[] newSubs, boolean exactMatch) with exactMatch=false, the original value of String s is not modified and is always returned - that is, the intended replacement value is never assigned to the return variable s.

      Example,

      String[] oldSubs =

      {"red", "orange", "yellow"}

      ;
      String[] newSubs =

      {"RED","ORANGE","YELLOW"}

      ;
      StringUtil.replace("red orange yellow", oldSubs, newSubs, false)

      Should replace all occurrences of the strings and return ...

      "RED ORANGE YELLOW"

      ... but instead returns ...

      "red orange yellow"

      To resolve, the code ...

      if (!exactMatch)

      { replace(s, oldSubs, newSubs); }

      else

      { ... }

      return s;

      ... should instead be ...

      if (!exactMatch) { s = replace(s, oldSubs, newSubs); }
      else { ... }

      return s;

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              shinn.lok Shinn Lok (Inactive)
              Reporter:
              james.hinkey James Hinkey
              Participants of an Issue:
              Recent user:
              Esther Sanz
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                9 years, 22 weeks, 2 days ago

                  Packages

                  Version Package
                  6.1.1 CE GA2
                  6.1.20 EE GA2
                  6.2.0 CE M2