Repository navigation
fix: transliterate non-Latin titles/filenames in _slugify() - #15
Merged
Merged
Conversation
_slugify() only kept [a-z0-9] characters, so a title in a non-Latin script (Telugu, Devanagari, etc. — Patr's own namesake, पत्र/పత్రం, is exactly this case) slugified to an empty string. new_edition() had no guard against that, so it would collide with any other non-Latin edition at CONTENT_DIR/"" instead of erroring cleanly, and every non-Latin image upload landed on the same image.jpg/image-<hex>.jpg fallback. Accented Latin text (e.g. "café") was also silently mangled rather than transliterated. Add unidecode to transliterate to ASCII before stripping non-alphanumerics, and fall back to "untitled" in new_edition() for titles with no transliterable characters at all (pure punctuation or emoji), matching the existing "image" fallback for uploads. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
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.
Summary
_slugify()only kept[a-z0-9], so a title in a non-Latin script (Telugu, Devanagari, etc. — Patr's own namesake, पत्र/పత్రం, is exactly this case) slugified to an empty string.new_edition()had no guard, so a second non-Latin-titled edition would silently collide atCONTENT_DIR/""instead of erroring cleanly, and every non-Latin image upload landed on the sameimage.jpg/image-<hex>.jpgfallback name."café") was also silently mangled (caf-na-ve) rather than transliterated.unidecode(MIT, no transitive deps) to transliterate to ASCII before stripping non-alphanumerics —"café"→"cafe","పత్రం"→"ptrn".new_edition()now falls back to"untitled"for titles with no transliterable characters at all (pure punctuation/emoji), matching the existing"image"fallback already used for uploads.Test plan
test_unicode_title_round_trips— the transliterated slug now includes the non-Latin part instead of dropping ituv run ruff check --unsafe-fixes --fix/uv run ruff formatuv run --extra dev pytest— 425 passed🤖 Generated with Claude Code