Report unterminated double-quoted values instead of dropping them - #618
Open
YoussefMansour9 wants to merge 1 commit into
Open
YoussefMansour9 wants to merge 1 commit into
YoussefMansour9 wants to merge 1 commit into
Conversation
When the input ended while still inside a double-quoted value, the buffered
content was discarded, so the entry and every line after it disappeared with
no error:
Dotenv::parse('FOO="bar'); // []
Dotenv::parse("A=\"oops\nB=keep"); // [] — B is swallowed too
The single-quoted path already reports a missing closing quote for the same
mistake, so a stray double quote silently erased configuration instead of
failing loudly.
`Lines::process()` now emits the still-open buffer once the input ends. The
parser then reports the same "missing closing quote" error the single-quoted
path produces, and stops swallowing the following lines. Properly closed
multiline values are unaffected.
Fixes vlucas#610
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.
Fixes #610.
What
When the input ends while still inside a double-quoted value, the entry and every
line after it are dropped with no error:
The single-quoted path already reports the mistake, so a stray double quote silently
erases configuration rather than failing loudly.
Why it happens
Lines::process()accumulates a multiline value in$multilineBufferand only appendsit to
$outputoncelooksLikeMultilineStop()matches. If the input ends while$multilineis still true, the loop simply exits and the buffer is discarded, taking theentry and every subsequent line with it.
The fix
Lines::process()now emits the still-open buffer once the input ends. The buffer reachesthe parser, which reports the same error the single-quoted path already produces:
Properly closed multiline values are unaffected, as are comments and whitespace.
On the version target
The linked issue suggests this belongs in the next major, since input that currently
returns an empty or partial array would start throwing. I have opened it against
masterbecause #615 made a comparable parsing change in this same method on this branch, but I am
happy to retarget if you would rather hold it.
Worth weighing in that decision: the current behaviour is silent data loss. Anything
relying on it is relying on a
.envtypo quietly wiping out the rest of the file.Tests
Three cases added to
DotenvTest: the unterminated value on its own, the case where itswallows a following line, and the single-quoted form as a control showing both now produce
the same error. The first two fail on
masterand pass with this change; the controlpasses either way.
Verified locally: full suite (283 tests),
phpstan analyzeclean, andsrc/Parser/Lines.phpat 34/34 statements covered.