fix: align the fast parser with the default parser - #1044
Open
chuanghiduoc wants to merge 1 commit into
Open
Conversation
parse(src, { fast: true }) diverged from parse(src) on three classes of
input:
1. A quoted value starting on a later line after `KEY=` — the default
regex's quoted alternative carries a greedy leading \s* that crosses
newlines, so the quote is consumed as the value. The fast scanner ended
the value at end-of-line, leaving the quoted text to be dropped. With a
blank line in between this silently turned secrets into ''.
2. \f, \v and U+00A0 before a key — the default parser skips them as \s,
the fast scanner discarded the whole line.
3. Trailing junk after a closing quote — 'TOKEN="abc" oops' now keeps the
raw single-line value '"abc" oops' like the default parser instead of
returning the clean quoted content.
The scanner now mirrors the regex engine: when a newline was crossed after
the separator only a quoted alternative can supply the value (the raw one
cannot span lines), any junk after its closing quote kills that alternative
leaving an empty value, and scanning resumes at the stray token so it can
still be parsed as its own entry.
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.
Follow-up to #1043. Aligns the fast parser with the default parser on all three divergence classes from the issue.
Changes
1. Quoted value starting on a later line after
KEY=The default regex's quoted alternative carries a greedy leading
\s*that crosses newlines, so a quote on a later line is consumed as the value. The scanner now detects when a newline was crossed after the separator and, if the next non-blank char is a quote, parses the value with full multiline support:Junk after the closing quote on that line still kills the whole alternative (the raw fallback cannot cross newlines), matching
A=\n\n"x" junk→{ A: '' }.2.
\f,\v, U+00A0 before a keyAdded to the whitespace-skip set alongside space/tab/newline/BOM:
3. Trailing junk after a closing quote
TOKEN="abc" oopsnow keeps the raw single-line value"abc" oops(the quoted form only survives when nothing but spaces/tabs or a comment follows the closing quote — anything else makes the raw[^\r\n#]+fallback take over starting at the opening quote, exactly like the regex backtracks).Tests
tests/test-fast-parity.js— parity assertions for the three issue cases; failed on master (5 fail), passes now.test-parse-fast.jscross-checks againsttests/.envand the multiline fixture: failed on master, passes with this change.Full suite on Windows:
201 total / 197 pass / 3 skip-adjacent fails— the 3 remaining failures (deals with file:// path,displays the injected env message without tips) are pre-existing environment failures that also fail on unmodified master.