Slice 3a: Path resolution + sanitization #4

Closed
opened 2026-06-03 10:26:54 +02:00 by AlexKucera · 0 comments
AlexKucera commented 2026-06-03 10:26:54 +02:00 (Migrated from github.com)

Parent

#1

What to build

Pure logic module for resolving output file paths from book metadata and sanitizing components for filesystem safety. No I/O, no network — all deterministic string manipulation.

downloader module (path logic):

  • Default conditional path pattern:
    • Book has series AND series_num: <FIRST_AUTHOR>/<SERIES_NAME>/Book <SERIES_NUM> <BOOK_TITLE>
    • Book has series but no series_num: <FIRST_AUTHOR>/<SERIES_NAME>/<BOOK_TITLE>
    • Book has no series: <FIRST_AUTHOR>/<BOOK_TITLE>
  • Custom path_pattern support with token substitution: FIRST_AUTHOR, ALL_AUTHORS, SERIES_NAME, SERIES_NUM, BOOK_TITLE, ISBN, FIRST_NARRATOR, ALL_NARRATORS, PUBLICATION_YEAR, PUBLICATION_MONTH, PUBLICATION_DAY
  • When custom pattern is set, it fully overrides the default conditional behavior

Sanitization rules (applied to every path component):

  1. Replace : characters with -
  2. Strip < > / \ | ? * and control characters (\x00-\x1F)
  3. Remove trailing dots
  4. Trim whitespace
  5. Cap component length at 255 characters
  6. Preserve: dashes, commas, apostrophes, parentheses, periods (non-trailing)

Subdirectory decision logic:

  • Given a book metadata object, determine whether a subdirectory is needed (based on presence of accompanying files — PDF extras or cover art)
  • This slice builds the function; actual subdirectory creation happens in later slices

Acceptance criteria

  • Default path resolves correctly for book with series + series_num
  • Default path resolves correctly for book with series but no series_num
  • Default path resolves correctly for book without series
  • Custom path_pattern with token substitution works for all documented tokens
  • Custom path_pattern overrides default when set
  • Colons replaced with - in all components
  • Illegal chars stripped: < > / \ | ? *
  • Control characters stripped
  • Trailing dots removed
  • Whitespace trimmed
  • Components capped at 255 chars
  • Dashes, commas, apostrophes, parentheses preserved
  • Subdirectory-needed returns True when PDF extras or cover art present
  • Subdirectory-needed returns False when neither present
  • ~20 tests covering all path patterns, every sanitization rule, edge cases (empty strings, max-length input, unicode)
  • All tests pass

Blocked by

#3

## Parent #1 ## What to build Pure logic module for resolving output file paths from book metadata and sanitizing components for filesystem safety. No I/O, no network — all deterministic string manipulation. **downloader module (path logic):** - Default conditional path pattern: - Book has series AND series_num: `<FIRST_AUTHOR>/<SERIES_NAME>/Book <SERIES_NUM> <BOOK_TITLE>` - Book has series but no series_num: `<FIRST_AUTHOR>/<SERIES_NAME>/<BOOK_TITLE>` - Book has no series: `<FIRST_AUTHOR>/<BOOK_TITLE>` - Custom `path_pattern` support with token substitution: FIRST_AUTHOR, ALL_AUTHORS, SERIES_NAME, SERIES_NUM, BOOK_TITLE, ISBN, FIRST_NARRATOR, ALL_NARRATORS, PUBLICATION_YEAR, PUBLICATION_MONTH, PUBLICATION_DAY - When custom pattern is set, it fully overrides the default conditional behavior **Sanitization rules** (applied to every path component): 1. Replace `:` characters with ` -` 2. Strip `< > / \ | ? *` and control characters (`\x00-\x1F`) 3. Remove trailing dots 4. Trim whitespace 5. Cap component length at 255 characters 6. Preserve: dashes, commas, apostrophes, parentheses, periods (non-trailing) **Subdirectory decision logic:** - Given a book metadata object, determine whether a subdirectory is needed (based on presence of accompanying files — PDF extras or cover art) - This slice builds the function; actual subdirectory creation happens in later slices ## Acceptance criteria - [ ] Default path resolves correctly for book with series + series_num - [ ] Default path resolves correctly for book with series but no series_num - [ ] Default path resolves correctly for book without series - [ ] Custom path_pattern with token substitution works for all documented tokens - [ ] Custom path_pattern overrides default when set - [ ] Colons replaced with ` -` in all components - [ ] Illegal chars stripped: `< > / \ | ? *` - [ ] Control characters stripped - [ ] Trailing dots removed - [ ] Whitespace trimmed - [ ] Components capped at 255 chars - [ ] Dashes, commas, apostrophes, parentheses preserved - [ ] Subdirectory-needed returns True when PDF extras or cover art present - [ ] Subdirectory-needed returns False when neither present - [ ] ~20 tests covering all path patterns, every sanitization rule, edge cases (empty strings, max-length input, unicode) - [ ] All tests pass ## Blocked by #3
Sign in to join this conversation.