From 1f43fd94fd03eef4bd7aea2c0c5d84ff465384fd Mon Sep 17 00:00:00 2001 From: Alex Forcier Date: Thu, 3 Dec 2020 13:06:59 +0900 Subject: [PATCH] Calculate end index of Story block relative to start Fixes a StringIndexOutOfBoundsException when the Story block is not the first block in the post. Previously the end of the first block would be matched, causing the substring end index to be earlier than the start index. --- .../android/ui/stories/SaveStoryGutenbergBlockUseCase.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/WordPress/src/main/java/org/wordpress/android/ui/stories/SaveStoryGutenbergBlockUseCase.kt b/WordPress/src/main/java/org/wordpress/android/ui/stories/SaveStoryGutenbergBlockUseCase.kt index 8dae05f35665..65c3ed0fce73 100644 --- a/WordPress/src/main/java/org/wordpress/android/ui/stories/SaveStoryGutenbergBlockUseCase.kt +++ b/WordPress/src/main/java/org/wordpress/android/ui/stories/SaveStoryGutenbergBlockUseCase.kt @@ -101,9 +101,10 @@ class SaveStoryGutenbergBlockUseCase @Inject constructor( while (storyBlockStartIndex > -1 && storyBlockStartIndex < content.length) { storyBlockStartIndex = content.indexOf(HEADING_START, storyBlockStartIndex) if (storyBlockStartIndex > -1) { + val storyBlockEndIndex = content.indexOf(HEADING_END, storyBlockStartIndex) val jsonString: String = content.substring( storyBlockStartIndex + HEADING_START.length, - content.indexOf(HEADING_END)) + storyBlockEndIndex) content = listener.doWithMediaFilesJson(content, jsonString) storyBlockStartIndex += HEADING_START.length }