Repository navigation
fix(output): preserve literal \n escape sequences in file content - #271
Open
Tyagiquamar wants to merge 1 commit into
Open
Tyagiquamar wants to merge 1 commit into
Tyagiquamar wants to merge 1 commit into
Conversation
9 tasks done
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #270.
Preserves literal
\n(and other escaped sequences) in file content when emitting output in text mode.Problem
In
src/lib.rs,concat_filesunescaped template newlines by running.replace("\\\\\n", "\n").replace("\\\\n", "\n")on the formatted string after interpolatingFILE_CONTENT.As reported in #270, if source file content contained literal
\nsequences (such astext.replace("\n", "\\n"),r"\nas", or regexes),yekin text mode silently transformed those literal escape sequences into real newline bytes (0x0A). This caused source files reconstructed fromyekdumps to differ byte-for-byte from the input and broke syntax in files like Python.Solution
Unescape template newlines in
output_templatebefore inserting file content rather than doing replacements on the concatenated output:output_templateonce viaconfig.output_template.as_ref().map(|t| t.replace("\\\\\n", "\n").replace("\\\\n", "\n")).FILE_PATHandFILE_CONTENTon the unescaped template.FILE_CONTENTis substituted last without subsequent string mutations, file content passes through byte-exact without escape sequence alteration.Verification
test_concat_files_preserves_literal_newlines_in_contentintests/lib_test.rsasserting byte-exact preservation of literal\n,\\n, and raw string escapes.cargo test --test lib_test -- test_concat_files: all 9 tests passed.rustfmt --check.