LANG-1610: Fix StringUtils.unwrap throws StringIndexOutOfBoundsException (#636)
Co-authored-by: Tony Liang <shuchel@zillowgroup.com>
This commit is contained in:
parent
bd8dbbe0be
commit
c6f577555b
|
@ -9342,7 +9342,7 @@ public class StringUtils {
|
|||
* @since 3.6
|
||||
*/
|
||||
public static String unwrap(final String str, final String wrapToken) {
|
||||
if (isEmpty(str) || isEmpty(wrapToken) || str.length() == 1) {
|
||||
if (isEmpty(str) || isEmpty(wrapToken) || str.length() < 2 * wrapToken.length()) {
|
||||
return str;
|
||||
}
|
||||
|
||||
|
|
|
@ -3174,6 +3174,7 @@ public class StringUtilsTest {
|
|||
assertEquals("abc", StringUtils.unwrap("abc", null));
|
||||
assertEquals("abc", StringUtils.unwrap("abc", ""));
|
||||
assertEquals("a", StringUtils.unwrap("a", "a"));
|
||||
assertEquals("ababa", StringUtils.unwrap("ababa", "aba"));
|
||||
assertEquals("", StringUtils.unwrap("aa", "a"));
|
||||
assertEquals("abc", StringUtils.unwrap("\'abc\'", "\'"));
|
||||
assertEquals("abc", StringUtils.unwrap("\"abc\"", "\""));
|
||||
|
|
Loading…
Reference in New Issue