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

Critical bug in StringUtil.equalsIgnoreCase

    Details

      Description

      Method StringUtil.equalsIgnoreCase(s1, s2) tries to be smart on comparing string ignoring case.
      It use uppercase and lowercase chars distance in ascii table to ignore case.

      Unfortunately if you compare "2001" with "R001" the function returns they are equals because the distance between "2" and "R" is -32, the same distance of "A" and "a".

      I suggest to change this porting of code

              for (int i = 0; i < s1.length(); i++) {
                  char c1 = s1.charAt(i);
      
                  char c2 = s2.charAt(i);
      
                  if (c1 == c2) {
                      continue;
                  }
      
                  if ((c1 > 127) || (c2 > 127)) {
      
                      // Georgian alphabet needs to check both upper and lower case
      
                      if ((Character.toLowerCase(c1) == Character.toLowerCase(c2)) ||
                          (Character.toUpperCase(c1) == Character.toUpperCase(c2))) {
      
                          continue;
                      }
      
                      return false;
                  }
      
                  int delta = c1 - c2;
      
                  if ((delta != 32) && (delta != -32)) {
                      return false;
                  }
              }
      

      with

              for (int i = 0; i < s1.length(); i++) {
                  char c1 = s1.charAt(i);
      
                  char c2 = s2.charAt(i);
      
                  if (c1 == c2) {
                      continue;
                  }
      
                  if ((c1 > 127) || (c2 > 127)) {
      
                      // Georgian alphabet needs to check both upper and lower case
      
                      if ((Character.toLowerCase(c1) == Character.toLowerCase(c2)) ||
                          (Character.toUpperCase(c1) == Character.toUpperCase(c2))) {
      
                          continue;
                      }
      
                      return false;
                  }
      
                  if ((Character.toLowerCase(c1) != Character.toLowerCase(c2)) {
                      return false;
                  }
              }
      
      

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              melody.wu Melody Wu
              Reporter:
              maumar Mauro Mariuzzo
              Participants of an Issue:
              Recent user:
              Marta Elicegui
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Days since last comment:
                4 years, 43 weeks, 6 days ago

                  Packages

                  Version Package
                  6.2.X EE
                  7.0.0 Beta 2