Repository navigation
fix(logfmt): read pre-escaping values as written - #19
Conversation
Lines written before v0.2.3 stored backslashes raw, so `C:\new` or a literal `\n` in prose was decoded as a newline on read. A line whose values use the escapes now ends with `esc=1`, and only fields before that marker are unescaped. Lines without it, and fields an older version appended after it, are read the old way, where only `\"` is an escape. Lines with no backslashes, newlines or tabs read the same either way and carry no marker, so most lines are unchanged. markSuperseded rewrites the whole line instead of appending to it, so a legacy row it touches comes out in the current format with the same values. Closes abogartz#14 Co-Authored-By: Claude Opus 5.5 <[email protected]>
Conflicts: test/logfmt.test.ts (import lines only). Union kept: the marker tests need config/memoryRoot + markSuperseded, main's abogartz#23 concurrency test needs appendLog/readLines. src/logfmt.ts auto-merged (their esc=1 reader/writer + main's appendFile O_APPEND) and was reviewed hunk-by-hunk; memory.ts likewise (appendMemory caps + markSuperseded whole-line rewrite are independent). Combined suite: 205 pass / 4 skip / 0 fail; tsc clean; biome lint exit 0.
|
Merge conflict resolved — merged current
Verified on the merged head: |
|
🎉 This PR is included in version 0.3.5 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Closes #14. This is the follow-up to #9, which caused the problem.
The issue left the choice to you, so treat this as a proposal. If you'd rather go with the document-only option, close this and I'll send that instead.
The problem: before v0.2.3, backslashes were stored raw. After #9, the reader decodes
\n,\t,\rand\as escapes everywhere, so an olderC:\new\tempor a literal"\n"in prose reads back with a real newline or tab. Some write paths then save the wrong value: the deletions audit log,clearSuperseded, and the viewer's edit box.Why a marker rather than a migration: there's no reliable way to tell an old line from a new one after the fact, and the store is shared between projects. A project that pins v0.2.2 keeps writing old-format lines into the same files after any one-time migration has run. A marker on new lines stays correct whatever mix of versions writes to the store.
Change
formatLineaddsesc=1at the end of a line only when one of its quoted values actually uses an escape (it contains a backslash, newline, CR or tab). Every other line is byte-for-byte what it was before.parseLineunescapes only the fields before the marker. Lines without it, and any field an older version appended after it, are read the old way, where only\"is an escape.escis never returned as a field.markSupersedednow rewrites the whole line throughformatLineinstead of appending fields to the raw line. A legacy row it touches comes out in the new format with its values unchanged. (Appending new-format fields to an old line would have mixed the two formats in one line.)esc=1inside a value is never read as a field. The single-line guarantee from fix: escape newlines and backslashes in logfmt values #9 is unchanged.One known gap: rows written by v0.2.3 to v0.3.0, which use escapes but have no marker, are read the old way. Their
\nshows as a literal backslash-n, and a backslash shows doubled. Only rows written in the day since v0.2.3 that contain a backslash, newline or tab are affected. The alternative would have misread every older row instead.Tests (
test/logfmt.test.ts)printf "%s\n") andC:\new\tempread back as written.esc=1round-trips.Checks:
bun test195 tests, 0 fail, 4 skip.tsc --noEmitis clean.biome lintreports no new findings in the touched files. Only standard Bun and TypeScript are used, so it behaves the same on macOS.🤖 Generated with Claude Code