From 57b64a412e858611d78914df96b51cdd1e05f964 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Tue, 16 Feb 2016 20:37:57 +0100 Subject: [PATCH] Fix infinite loop when no chapter number is parsed --- .../kanade/tachiyomi/util/ChapterRecognition.java | 15 +++++++++------ .../kanade/tachiyomi/ChapterRecognitionTest.java | 7 +++++++ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/util/ChapterRecognition.java b/app/src/main/java/eu/kanade/tachiyomi/util/ChapterRecognition.java index 045b4609e1..812916e546 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/util/ChapterRecognition.java +++ b/app/src/main/java/eu/kanade/tachiyomi/util/ChapterRecognition.java @@ -111,12 +111,15 @@ public class ChapterRecognition { } // Strip anything after "part xxx" and try that - name = pPart.matcher(name).replaceAll("$1"); - dummyChapter.name = name; - parseChapterNumber(dummyChapter, manga); - if (dummyChapter.chapter_number >= 0) { - chapter.chapter_number = dummyChapter.chapter_number; - return; + matcher = pPart.matcher(name); + if (matcher.find()) { + name = pPart.matcher(name).replaceAll("$1"); + dummyChapter.name = name; + parseChapterNumber(dummyChapter, manga); + if (dummyChapter.chapter_number >= 0) { + chapter.chapter_number = dummyChapter.chapter_number; + return; + } } } diff --git a/app/src/test/java/eu/kanade/tachiyomi/ChapterRecognitionTest.java b/app/src/test/java/eu/kanade/tachiyomi/ChapterRecognitionTest.java index 28ad19ed89..150520ad50 100644 --- a/app/src/test/java/eu/kanade/tachiyomi/ChapterRecognitionTest.java +++ b/app/src/test/java/eu/kanade/tachiyomi/ChapterRecognitionTest.java @@ -172,4 +172,11 @@ public class ChapterRecognitionTest { ChapterRecognition.parseChapterNumber(c, randomManga); assertThat(c.chapter_number).isEqualTo(027f); } + + @Test + public void testUnparsable() { + Chapter c = createChapter("Foo"); + ChapterRecognition.parseChapterNumber(c, randomManga); + assertThat(c.chapter_number).isEqualTo(-1f); + } }