commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "HiuFung Kwok (JIRA)" <>
Subject [jira] [Commented] (LANG-1406) StringIndexOutOfBoundsException in StringUtils.replaceIgnoreCase
Date Wed, 08 Aug 2018 12:02:00 GMT


HiuFung Kwok commented on LANG-1406:

Hi all,

After a bit of research, it seem to be a known issue when unicode is contained on a String
object([ref|[])], String.toLowerCase()
would produce a incorrect result.

In this case "\u0130" would become a String object with three char which are [ i,  ̇,
x] instead of [ İ, x].

So by given a incorrect result from .toLowCase() method, StringUtils.replaceIgnoreCase end
attempt to access the segment of string which is not exist which is 3 in this case while str.length()
is 2.

The fixture I come up with is replacing the .toLowcase() to .toUpperCase() in order to avoid
the mis-interprettion on .toLowerCase while performing case-insensitive comparisons.

Fixture: []




> StringIndexOutOfBoundsException in StringUtils.replaceIgnoreCase
> ----------------------------------------------------------------
>                 Key: LANG-1406
>                 URL:
>             Project: Commons Lang
>          Issue Type: Bug
>          Components: lang.*
>            Reporter: Michael Ryan
>            Priority: Major
> {code}
> StringUtils.replaceIgnoreCase("\u0130x", "x", "")
> {code}
> EXPECTED: "\u0130" is returned.
> ACTUAL: StringIndexOutOfBoundsException
> This happens because the replace method is assuming that text.length() == text.toLowerCase().length(),
which is not true for certain characters.

This message was sent by Atlassian JIRA

View raw message