From e22f6c517f798cb033a3bc0104bd150937bd20fc Mon Sep 17 00:00:00 2001 From: Aditya Sharat Date: Fri, 18 Sep 2020 11:59:38 -0700 Subject: [PATCH] Fixes StringIndexOutOfBoundsException caused by ellipsis offset. Summary: Fixes StringIndexOutOfBoundsException caused by ellipsis offset. Overrides the offset if it is greater than the length of the text. Reviewed By: astreet Differential Revision: D23756985 fbshipit-source-id: 11f6ef5314a4349e2cb5aa74937b546104e8e938 --- .../src/main/java/com/facebook/litho/widget/TextSpec.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/litho-widget/src/main/java/com/facebook/litho/widget/TextSpec.java b/litho-widget/src/main/java/com/facebook/litho/widget/TextSpec.java index 66da765f3ab..2c9e2b99a32 100644 --- a/litho-widget/src/main/java/com/facebook/litho/widget/TextSpec.java +++ b/litho-widget/src/main/java/com/facebook/litho/widget/TextSpec.java @@ -799,6 +799,11 @@ private static CharSequence truncateText( ellipsisOffset = ellipsisStart; } } + if (ellipsisOffset < 0) { + ellipsisOffset = 0; + } else if (ellipsisOffset > text.length()) { + ellipsisOffset = text.length(); + } return TextUtils.concat(text.subSequence(0, ellipsisOffset), customEllipsisText); } else { return text;