From 887c383229c4634deda731cde9a3db3fede94709 Mon Sep 17 00:00:00 2001 From: Timmy Welch Date: Mon, 29 Apr 2024 10:09:59 -0700 Subject: [PATCH] Fix an infinite loop issue parsing numbers outside of 0-9 fixes #639 --- comicapi/filenamelexer.py | 7 +++++-- testing/filenames.py | 15 +++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/comicapi/filenamelexer.py b/comicapi/filenamelexer.py index d4d4cec..5424bc8 100644 --- a/comicapi/filenamelexer.py +++ b/comicapi/filenamelexer.py @@ -146,7 +146,8 @@ class Lexer: return False # AcceptRun consumes a run of runes from the valid set. - def accept_run(self, valid: str | Callable[[str], bool]) -> None: + def accept_run(self, valid: str | Callable[[str], bool]) -> bool: + initial = self.pos if isinstance(valid, str): while self.get() in valid: continue @@ -155,11 +156,13 @@ class Lexer: continue self.backup() + return initial != self.pos def scan_number(self) -> bool: digits = "0123456789.," - self.accept_run(digits) + if not self.accept_run(digits): + return False if self.input[self.pos] == ".": self.backup() self.accept_run(str.isalpha) diff --git a/testing/filenames.py b/testing/filenames.py index 6c858fe..58612ea 100644 --- a/testing/filenames.py +++ b/testing/filenames.py @@ -438,6 +438,21 @@ names: list[tuple[str, str, dict[str, str | bool], tuple[bool, bool]]] = [ }, (False, False), ), + ( + "Blue Beetle #½.cbr", + "½", + { + "archive": "cbr", + "issue": "½", + "series": "Blue Beetle", + "title": "", + "volume": "", + "year": "", + "remainder": "", + "issue_count": "", + }, + (False, True), + ), ( "Monster Island vol. 2 #2.cbz", "Example from userguide",