Commit Graph
3 Commits
Author SHA1 Message Date
kevin9327andClaude Opus 5 28ef19dcc6 fix(import): read UTF-32 marks, and survive a non-text declaration
Two Greptile P1s on this PR, both real:

- A UTF-32 LE byte-order mark starts with the UTF-16 LE one, so the BOM
  table matched UTF-16 first, stripped two bytes and read the file as
  NUL-interleaved UTF-16; a UTF-32 BE mark matched nothing and fell through
  to Windows-1252. The table lives in services.text_upload and is shared, so
  /dub/import-srt and the .txt/.md branch of /audiobook/import carried the
  same corruption -- it is fixed once, longest mark first, and both front
  doors and the EPUB path inherit it.
- A declaration such as encoding="hex_codec" passes codecs.lookup but
  bytes.decode refuses it with LookupError, which would have failed the
  whole EPUB import. The codecs.lookup pre-check is gone: the decode itself
  decides, and an encoding that cannot produce text now guesses like an
  undeclared document does.

text_upload gains bom_encoding() so the EPUB path asks the one table rather
than keeping a second copy of it.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-18 07:44:30 +09:00
kevin9327andClaude Opus 5 ad4b3547d4 fix(import): an undefined Windows-1252 byte no longer spoils the whole file
Review follow-up. A Windows-1252 upload with one of the five bytes cp1252
leaves undefined fell back to decoding the entire file as Latin-1, so its
curly quotes, dashes and euro signs became C1 control characters. Only
the undefined bytes now take their Latin-1 code point, which is what the
browser's windows-1252 decoder does, so readTextFile and
decode_text_upload agree byte for byte.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 08:21:52 +09:00
kevin9327andClaude Opus 5 c8c833062b fix(import): read UTF-16 and Windows-1252 subtitles and manuscripts
/dub/import-srt fell back to Latin-1 when UTF-8 failed, so a UTF-16 .srt
(Notepad's "Unicode", many subtitle editors) decoded with a NUL between
every character and was rejected as having no cues, and a Windows-1252
one turned curly quotes and dashes into C1 control characters.
/audiobook/import decoded .txt/.md with errors="ignore", silently dropping
every accent, dash and curly quote from a Windows-1252 manuscript,
returning NUL-interleaved text for a UTF-16 one, and keeping a UTF-8 BOM
at the start of the editor text.

Both now use decode_text_upload: a BOM names the encoding, valid UTF-8
stays UTF-8, and anything else is read as Windows-1252, with Latin-1 for
the bytes cp1252 leaves undefined so the decode never raises.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-09-14 08:14:46 +09:00