fix: do not strip boundary quotes from unquoted values#1030
Open
spokodev wants to merge 1 commit into
Open
Conversation
An unquoted value that happens to start and end with the same quote character (e.g. JSON="a":"b") was matched by the unquoted LINE alternative, then had its first and last quote stripped by the surrounding-quote replace, yielding a":"b instead of "a":"b". The strip fired whenever a value merely began and ended with a quote, without checking it was actually a wrapped quoted token. Gate the strip (and the double-quote newline expansion) on the value being a fully wrapped quoted token, matched with the same single/double/backtick alternatives the LINE regex allows. README documents that inner quotes are maintained (think JSON); this makes the parser honor that for values whose boundary characters are quotes.
LuxeGold25-coder
left a comment
There was a problem hiding this comment.
What is the payload account that is connected
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.
The bug
An unquoted value that happens to start and end with the same quote character has those boundary quotes stripped:
Why this is wrong
The README documents that inner quotes are maintained (line 447, "think JSON"):
"a":"b"is the same shape: a value whose quote characters are content, not a wrapper. It only differs in that its quote characters land on the boundary. The first and last"are part of the value, so they should be kept.This also matters for shell / dotenvx interop. In a POSIX shell,
JSON="a":"b"assigns the literala:b(each"..."is a separate quoted span the shell concatenates), and dotenvx-style consumers expect the raw token to round-trip. Silently deleting the outer quotes produces a value (a":"b) that matches neither the shell result nor the documented JSON-style behavior.Root cause
The value
"a":"b"cannot match the double-quotedLINEalternative"(?:\\"|[^"])*"because the unescaped inner"blocks a clean wrap, so it falls through to the unquoted alternative[^#\r\n]+and is captured raw.The surrounding-quote strip then runs unconditionally:
That regex fires on any value whose first and last characters are the same quote char, without verifying the value was actually captured as a wrapped quoted token. So an unquoted value gets its boundary quotes deleted.
The fix
Strip the surrounding quotes (and run the double-quote
\n/\rexpansion) only when the value is a fully wrapped quoted token, matched with the same single/double/backtick alternatives theLINEregex itself allows:A genuinely quoted value (
"x",'x',`x`) still matchesQUOTEDand is stripped exactly as before. An unquoted value whose boundary characters happen to be quotes does not match, so its quotes are preserved.Red -> green
Added a fixture line
RETAIN_BOUNDARY_QUOTES_UNQUOTED="a":"b"totests/.envand an assertion intests/test-parse.js:Fails before the fix (parses to
a":"b), passes after.Full suite green:
{ total: 200, pass: 200 }(lint + dts-check + all parse / multiline / config / populate tests, including every existing single/double/backtick quote,\nexpansion, and theRETAIN_INNER_QUOTESfixtures).