Don't read a number inside a scanner tag as the issue number - #547
Closed
andreasorbelli wants to merge 1 commit into
Closed
Don't read a number inside a scanner tag as the issue number#547andreasorbelli wants to merge 1 commit into
andreasorbelli wants to merge 1 commit into
Conversation
The parser strips parenthetical groups before looking for the number, with a
comment saying year groups must not interfere with finding the last digit
sequence. Square brackets carry the same noise — resolutions, years, scanner
handles — and were left in.
The three-or-more-digit rule takes the LAST match and wants whitespace on both
sides, so a number in the middle of a tag beats the real issue number, while
one that opens or closes the tag is safe:
Daredevil 012 [c2c 1440 px].cbz -> 1440, not 12
Hellblazer 25 [Minutemen 2011 ed].cbz -> 2011, not 25
Preacher 007 [1280 web].cbz -> 7 (already right)
The failure is silent. The file matches a real issue, just the wrong one, and
metadata is written with no warning. From the measurement in allaboutduncan#540, over a real
library: Topolino 0330 (Mondadori 1962-03-25) [c2c Hal 2008 & Bibbo64].cbr is
tagged as issue #2008 published 1994, when it is allaboutduncan#330 from 1962.
So strip bracketed groups where parenthetical groups are already stripped.
This is the three-or-more-digit rule only: the one- and two-digit rule runs
against the raw name and takes its first match rather than its last, so it is
not exposed the same way and is left alone.
It costs one thing, and there is a test pinning it: an issue number that only
ever appears inside brackets stops being found. No convention writes them that
way, and such a file falls back to the remaining rules rather than being
mistagged, but it should be a recorded decision rather than a surprise.
Closes allaboutduncan#545
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01MTCdHCCLmS4uMZG9NZWTz6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Description
Closes #545
extract_issue_numberstrips parenthetical groups before looking for the number — the commentthere says year groups must not interfere with finding the last digit sequence. Square brackets
carry the same kind of noise, resolutions and years and scanner handles, and were left in.
The three-or-more-digit rule takes the last match and requires whitespace on both sides, so a
number in the middle of a tag beats the real issue number, while one that opens or closes the tag
is safe:
mainDaredevil 012 [c2c 1440 px].cbzHellblazer 25 [Minutemen 2011 ed].cbzBatman 001 (2016) [Empire 2015 rescan].cbzTopolino 0330 (Mondadori 1962-03-25) [c2c Hal 2008 & Bibbo64].cbrPreacher 007 [1280 web].cbzBatman 001 (2016) [digital] [Empire 2015].cbzTex 700 [c2c].cbzThe failure is silent: the file matches a real issue, just the wrong one, and metadata is written
with no warning. The last row of the first group is not constructed — it came out of the
measurement in #540, over a real library, where the file is tagged as issue #2008 published 1994
when it is issue #330 from 1962.
Which paths this reaches
core/bulk_metadata.pycallsextract_issue_numberdirectly, so a bulk run is exposed for everyname in the table.
/api/search-metadataparses with the rename parser first and only falls backto
extract_issue_numberwhen that yields no issue number — so it is exposed for some of these andnot others, which is worth being precise about:
So the same filename can tag correctly through one path and incorrectly through another, which is
part of why it is hard to spot from the outside.
The change
Strip bracketed groups where parenthetical groups are already stripped, as properly-paired
alternatives so a
(…)containing a[…]is still handled as one group. That is thethree-or-more-digit rule only. The one- and two-digit rule runs against the raw name and takes its
first match rather than its last, so it is not exposed the same way, and leaving it alone keeps
the change on the path that is actually wrong.
What it costs. An issue number that only ever appears inside brackets stops being found —
Daredevil [012].cbzreturns nothing rather than 12. No convention writes them that way, and sucha file falls back to the remaining rules rather than being mistagged, but there is a test pinning
it so it stays a recorded decision rather than a later surprise.
🛠️ Changes Made
docker build -t dev .)Two files: the parser in
models/providers/base.py, and the tests. +42 / −4.📸 Screenshots / Logs
Both parsers, run inside the built images —
mainat d8e046e and this branch — so the numbersabove are what the shipped code does, not what the test suite mocks:
🧪 Testing Performed
devcontainer — the parse comparison aboveTwelve new cases in
tests/unit/test_provider_base.py: the four broken shapes, the four thatalready parsed correctly and must keep doing so, both group kinds together in either order, the
bracket-only number that is the cost of the change, and an unterminated bracket, which is left
untouched exactly as an unterminated parenthesis always was. Six fail on
main— the four brokenshapes and the two mixed ones; the rest pass either way and are there as guards.
Every existing case in that file is unchanged and still passes, including the ones the docstring
advertises (
Spider-Man 2099 001 (1992),Amazing Spider-Man (2018) Issue 080.BEY,Gen 13 013A)and the filename from #223, the
V2021bug you closed earlier in this same family.🤖 Generated with Claude Code
https://claude.ai/code/session_01MTCdHCCLmS4uMZG9NZWTz6