You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Text output corrupts file content: literal "\n" escape sequences in source are rewritten as real newlines (0.25.0 & 0.26.0 tested) #270
yek in its default (text) output mode silently rewrites parts of file
content. Occurrences of the literal two-character sequence \n (backslash +
n) that appear inside source strings are converted into real newline
bytes (0x0A) in the output. The output therefore does not round-trip:
files reconstructed from a yek dump are not byte-identical to the inputs,
and Python files can become syntactically invalid ("unterminated string
literal").
The --json output mode is unaffected (byte-exact).
Environment
yek version: 0.26.0 (also observed on the version installed by curl -fsSL https://proofline.sh/yek/install.sh | bash on Linux x86_64)
OS: Linux (reproduced independently on two different machines)
Invocation: yek . --output-dir out and yek . (stdout), both affected
The chunk content is byte-identical to the input file; the .replace(...)
lines each stay on a single physical line, exactly as in the source.
Actual
The three lines whose replacement argument is the two-character sequence \n are split across two lines: the sequence is emitted as a real newline
byte inside the string literal:
(cat -A output; $ marks a real line ending — note the string literal
now contains a raw 0x0A, so the emitted file is invalid Python.)
Other affected shapes seen in a real repository dump:
value=r"\nas"# → value = r"<real LF>as"" text = '\n'.join(data_lines)\n"# mid-string \n becomes a real LF
while other escape sequences next to them (\;, \,, \t, \r, \\) are
passed through untouched — the rewrite is specific to \n.
Impact
In our case (a Flask codebase of ~2100 files), 7 files were corrupted in a
35 MB dump, including the module that escapes CR/LF in user-controlled
text before writing iCalendar feeds — i.e. the security control itself was
mangled, and the corruption is easy to miss because the dump looks fine
in a text editor with soft wrap.
Workaround
yek --json produces byte-exact content (verified with a full
diff against the original files), presumably because the content is
JSON-escaped instead of being written through the text template.
Suggested fix
Write chunk content as raw bytes without any escape processing in the
default text template path (>>>> {path}\n{content}), or escape backslashes
when templating. The invariant worth a test: yek output must round-trip
every input file byte-for-byte (--json already does; text mode should
too).
changed the title [-]Text output corrupts file content: literal "\n" escape sequences in source are rewritten as real newlines (0.26.0)[/-][+]Text output corrupts file content: literal "\n" escape sequences in source are rewritten as real newlines (0.25.0 & 0.26.0 tested)[/+]on Nov 25, 2026
Activity
[-]Text output corrupts file content: literal "\n" escape sequences in source are rewritten as real newlines (0.26.0)[/-][+]Text output corrupts file content: literal "\n" escape sequences in source are rewritten as real newlines (0.25.0 & 0.26.0 tested)[/+]