Fix potential offset errors in BasicJsonParser

Update BasicJsonParser to fix potential exceptions if strings happen
to be empty.

Fixes gh-6136
This commit is contained in:
Ivan Sopov 2016-06-10 11:48:06 -07:00 committed by Phillip Webb
parent ed6f11d60d
commit 1528764194

View File

@ -93,14 +93,14 @@ public class BasicJsonParser implements JsonParser {
}
private static String trimTrailingCharacter(String string, char c) {
if (string.length() >= 0 && string.charAt(string.length() - 1) == c) {
if (string.length() > 0 && string.charAt(string.length() - 1) == c) {
return string.substring(0, string.length() - 1);
}
return string;
}
private static String trimLeadingCharacter(String string, char c) {
if (string.length() >= 0 && string.charAt(0) == c) {
if (string.length() > 0 && string.charAt(0) == c) {
return string.substring(1);
}
return string;