Repository navigation
Slugify uploaded filenames; cap image height too - #10
Merged
Merged
Conversation
Uploaded filenames were saved as-is (spaces, mixed case, and mixed- case extensions all preserved). Traced from a real user's repo: an uploaded "Map of Living Room.PNG" broke an external pre-commit hook doing further image compression — pngquant's --ext .png treats "name.PNG" -> "name.png" as a *different* filename (case-sensitive), silently leaving an untracked derivative file behind on every commit that touched it. _slugify() (extracted from the existing edition-slug logic in new_edition() — same lowercase-hyphenated convention, now shared) is applied to the upload's filename stem before saving, falling back to "image" if the name slugifies to nothing (e.g. "!!!.png"). This avoids the whole class of case-sensitivity/whitespace problems regardless of what any downstream tooling (git hooks, shell scripts, URL encoding) does with the file, rather than only patching around the one script that happened to break on it. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
3 tasks done
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
Two related fixes to image uploads, both traced from a real user's repo:
1. Slugify uploaded filenames
An uploaded
"Map of Living Room.PNG"broke an external pre-commit hook doing further image compression —pngquant --ext .pngtreats"name.PNG"→"name.png"as a different filename (case-sensitive), silently leaving an untracked derivative file behind on every commit that touched it._slugify()from the existing edition-slug logic innew_edition()(same lowercase-hyphenated convention) — now shared.upload_image()applies it to the upload's filename stem before saving, falling back to"image"if the name slugifies to nothing (e.g."!!!.png").Fixes the class of problem at the source (spaces, mixed case, mixed-case extensions) rather than only patching around the one script that happened to break on it.
2. Cap image height, not just width
While investigating, found
compress_image()only ever checkedimg.widthagainst the max dimension — a tall portrait image (narrow width, huge height) sailed through completely unresized, since its width alone was never over the threshold.Swapped the width-only check for
Image.thumbnail(), which bounds both width and height in one call (only ever shrinks, preserves aspect ratio). RenamedIMAGE_MAX_WIDTH→IMAGE_MAX_DIMENSIONto match its new meaning.Test plan
uv run ruff check --unsafe-fixes --fix/uv run ruff formatuv run --extra dev pytest(417 passed) — 4 new tests (slugify: spaces+mixed case, special characters, empty-after-slugify fallback; portrait-image height cap), each verified red before the fix🤖 Generated with Claude Code