diff options
Diffstat (limited to 'vespajlib')
-rw-r--r-- | vespajlib/src/main/java/com/yahoo/text/Text.java | 7 | ||||
-rw-r--r-- | vespajlib/src/test/java/com/yahoo/text/TextTestCase.java | 1 |
2 files changed, 7 insertions, 1 deletions
diff --git a/vespajlib/src/main/java/com/yahoo/text/Text.java b/vespajlib/src/main/java/com/yahoo/text/Text.java index 2f0051d4795..a2e7a696857 100644 --- a/vespajlib/src/main/java/com/yahoo/text/Text.java +++ b/vespajlib/src/main/java/com/yahoo/text/Text.java @@ -186,7 +186,12 @@ public final class Text { int len = s.length(); if ((fromCP >= len) || (fromCP >= toCP)) return ""; - int from = s.offsetByCodePoints(0, fromCP); + int from; + try { + from = s.offsetByCodePoints(0, fromCP); + } catch (IndexOutOfBoundsException e) { + return ""; + } if (from >= len) return ""; int lenCP = toCP - fromCP; if (from + lenCP >= len) return s.substring(from); diff --git a/vespajlib/src/test/java/com/yahoo/text/TextTestCase.java b/vespajlib/src/test/java/com/yahoo/text/TextTestCase.java index 2639882230f..c82eba0246f 100644 --- a/vespajlib/src/test/java/com/yahoo/text/TextTestCase.java +++ b/vespajlib/src/test/java/com/yahoo/text/TextTestCase.java @@ -73,6 +73,7 @@ public class TextTestCase { String withSurrogates = fromCP("abc", new int[]{0x10F000, 0x10F001, 0x10F002}, "def"); assertEquals(withSurrogates, Text.substringByCodepoints(withSurrogates, 0, 11)); assertEquals(withSurrogates, Text.substringByCodepoints(withSurrogates, 0, 20)); + assertEquals("", Text.substringByCodepoints(withSurrogates, 10, 11)); assertEquals(fromCP("bc", new int[]{0x10F000, 0x10F001}, ""), Text.substringByCodepoints(withSurrogates, 1, 5)); assertEquals(fromCP("", new int[]{0x10F001}, ""), |