Skip to content

Accept CRLF source files and normalize them to LF (#25)#66

Merged
jmacdotorg merged 2 commits into
masterfrom
fix/25-crlf-newlines
Jun 22, 2026
Merged

Accept CRLF source files and normalize them to LF (#25)#66
jmacdotorg merged 2 commits into
masterfrom
fix/25-crlf-newlines

Conversation

@jmacdotorg

Copy link
Copy Markdown
Owner

Closes #25.

Diagnosis

Source files with CRLF ("Windows") newlines used to break publication with a misleading The "time" attribute is not in W3C format. error. The cause was the old metadata regex (.*)$ capturing the trailing \r into attribute values, so time became 2018-03-04T12:00:00\r and failed the W3C parse.

Commit 920dbdf (2020-05-07) tightened that regex to (.*?)\s*$, which strips trailing whitespace and incidentally cured the crash — the issue just was never closed. Today a CRLF file already publishes successfully. The one remaining wrinkle: the in-place source rewrite kept CRLF in the post body, leaving the source file with mixed line endings (LF metadata + CRLF body).

Fix

Normalize \r\n (and bare \r) to \n as each line is read, in both the metadata and body loops of _process_source_file. Metadata parsing is now robust by construction rather than by regex accident, and the rewritten source comes out uniformly LF.

Test

Adds t/crlf.t: writes a raw-CRLF source file, then asserts it publishes without error, produces its HTML, and that the rewritten source contains no carriage returns. Before the fix only the carriage-return assertion failed (confirming the crash itself was already gone); it passes now. Full suite green (81 tests).

🤖 Generated with Claude Code

jmacdotorg and others added 2 commits June 21, 2026 19:59
CRLF ("Windows") source files historically broke publication with a
misleading "not in W3C format" error, because the old metadata regex
captured the trailing carriage return into attribute values. That regex
was tightened in 920dbdf, which incidentally cured the crash, but the
in-place source rewrite still left CRLF newlines in the body, producing
a source file with mixed line endings.

Normalize CRLF (and bare CR) to LF as each line is read, in both the
metadata and body loops of _process_source_file, so parsing is robust by
construction and the rewritten source comes out uniformly LF.

Adds t/crlf.t covering publication and clean rewriting of a CRLF source.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Address review feedback: rather than repeating the normalization regex in
both the metadata and body read loops, factor it into a single
_normalize_newlines subroutine.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jmacdotorg jmacdotorg merged commit 8945f71 into master Jun 22, 2026
3 checks passed
@jmacdotorg jmacdotorg deleted the fix/25-crlf-newlines branch June 22, 2026 14:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CRLF newlines in source files mess up publication

1 participant