Skip to content

fix(dotenv): strip trailing carriage return when parsing CRLF files - #2293

Open
x1247897956 wants to merge 1 commit into
getsops:mainfrom
x1247897956:fix/dotenv-crlf-parsing
Open

fix(dotenv): strip trailing carriage return when parsing CRLF files#2293
x1247897956 wants to merge 1 commit into
getsops:mainfrom
x1247897956:fix/dotenv-crlf-parsing

Conversation

@x1247897956

Copy link
Copy Markdown

What

Fix dotenv parsing so CRLF (\r\n) line endings no longer corrupt decrypted values.

sops/stores/dotenv/store.go's LoadPlainFile splits input on \n but never strips the trailing \r. On files with Windows/CRLF line endings, every value ends up with a stray carriage return ("val1\r"), comments carry \r, and empty lines become \r-only lines that are treated as malformed input.

Why

This is the same underlying symptom reported in #854, #1128, and #1157 — encrypted dotenv files that fail to decrypt (or silently corrupt values) after their line endings are converted to CRLF, e.g. by git on Windows.

Fix

Strip a single trailing \r from each line before processing. This is additive and backward compatible: LF-only files behave exactly as before.

Tests

Added TestLoadPlainFileCRLF asserting that a CRLF file with values and a comment parses identically to its LF counterpart. go test ./stores/dotenv/ passes.

Signed-off-by: Mrxh x1247897956@users.noreply.github.com

Signed-off-by: Mrxh <x1247897956@users.noreply.github.com>
@felixfontein
felixfontein requested a review from a team September 7, 2026 03:27
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.

1 participant