@@ -95,6 +95,66 @@ t.test('fast parse matches classic parse for an escaped backslash before the clo
9595 ct . end ( )
9696} )
9797
98+ // Regressions reported in https://github.com/motdotla/dotenv/issues/1043,
99+ // including the unterminated quote and separate quoted segments follow-up.
100+ // Pin the classic result next to each fast assertion so parity cannot pass
101+ // simply because both parsers return the same incorrect result.
102+ const parityRegressions = [
103+ {
104+ name : 'blank line before a quoted multiline value' ,
105+ src : 'A=\n\n"hello\nworld"' ,
106+ expected : { A : 'hello\nworld' }
107+ } ,
108+ {
109+ name : 'quoted value on the next line' ,
110+ src : "A=\n'b'" ,
111+ expected : { A : 'b' }
112+ } ,
113+ {
114+ name : 'form feed before a key' ,
115+ src : '\fA=1' ,
116+ expected : { A : '1' }
117+ } ,
118+ {
119+ name : 'vertical tab before a key' ,
120+ src : '\vA=1' ,
121+ expected : { A : '1' }
122+ } ,
123+ {
124+ name : 'non-breaking space before a key' ,
125+ src : '\u00A0A=1' ,
126+ expected : { A : '1' }
127+ } ,
128+ {
129+ name : 'trailing junk after a closing quote' ,
130+ src : 'TOKEN="abc" oops' ,
131+ expected : { TOKEN : '"abc" oops' }
132+ } ,
133+ {
134+ name : 'escaped newline in an unterminated double-quoted value' ,
135+ src : 'KEY="line one\\nline two' ,
136+ expected : { KEY : '"line one\nline two' }
137+ } ,
138+ {
139+ name : 'escaped carriage return in an unterminated double-quoted value' ,
140+ src : 'KEY="line one\\rline two' ,
141+ expected : { KEY : '"line one\rline two' }
142+ } ,
143+ {
144+ name : 'separate quoted segments on one line' ,
145+ src : 'KEY="a" "b"' ,
146+ expected : { KEY : 'a" "b' }
147+ }
148+ ]
149+
150+ for ( const { name, src, expected } of parityRegressions ) {
151+ t . test ( `issue #1043: ${ name } ` , ct => {
152+ ct . same ( dotenv . parse ( src ) , expected , 'classic parser returns the expected value' )
153+ ct . same ( dotenv . parse ( src , { fast : true } ) , expected , 'fast parser returns the same expected value' )
154+ ct . end ( )
155+ } )
156+ }
157+
98158t . test ( 'config({ fast: true }) reads a .env written with a BOM' , ct => {
99159 const processEnv = { }
100160 const result = dotenv . config ( {
0 commit comments