File tree 2 files changed +28
-12
lines changed
2 files changed +28
-12
lines changed Original file line number Diff line number Diff line change @@ -365,23 +365,36 @@ export const parseDotenv = (content: string): NodeJS.ProcessEnv => {
365
365
let k = ''
366
366
let c = ''
367
367
let q = ''
368
+ let i = false
368
369
const cap = ( ) => { if ( c && k ) {
369
370
if ( ! r . test ( k ) ) throw new Error ( `Invalid identifier: ${ k } ` )
370
371
e [ k ] = c ; c = '' ; k = ''
371
372
} }
372
373
373
374
for ( const s of content ) {
374
- if ( s === ' ' && ! q ) {
375
- if ( ! k && c === 'export ' ) c = ''
375
+ if ( i ) {
376
+ if ( s === '\n ' ) i = false
376
377
continue
377
378
}
378
- if ( s === '=' && ! q ) {
379
- if ( ! k ) { k = c ; c = '' ; continue }
380
- }
381
- if ( s === '\n' && ! q ) {
382
- cap ( )
383
- continue
379
+ if ( ! q ) {
380
+ if ( s === '#' ) {
381
+ i = true
382
+ continue
383
+ }
384
+ if ( s === ' ' ) {
385
+ if ( ! k && c === 'export' ) c = ''
386
+ continue
387
+ }
388
+ if ( s === '=' ) {
389
+ if ( ! k ) { k = c ; c = '' ; continue }
390
+ }
391
+ if ( s === '\n' ) {
392
+ i = false
393
+ cap ( )
394
+ continue
395
+ }
384
396
}
397
+
385
398
if ( s === '"' || s === "'" ) {
386
399
if ( q === s ) {
387
400
q = ''
Original file line number Diff line number Diff line change @@ -141,24 +141,27 @@ describe('util', () => {
141
141
assert . equal ( toCamelCase ( 'kebab-input-str' ) , 'kebabInputStr' )
142
142
} )
143
143
144
- test ( 'parseDotenv()' , ( ) => {
144
+ test . only ( 'parseDotenv()' , ( ) => {
145
145
const multiline = `SIMPLE=xyz123
146
- NON_INTERPOLATED='raw text without variable interpolation'
146
+ # comment ###
147
+ NON_INTERPOLATED='raw text without variable interpolation'
147
148
MULTILINE = """
148
- long text here,
149
+ long text here, # not-comment
149
150
e.g. a private SSH key
150
151
"""
151
152
ENV=v1\nENV2=v2\n\n\n ENV3 = v3 \n export ENV4=v4
153
+ ENV5=v5 # comment
152
154
`
153
155
154
156
assert . deepEqual ( parseDotenv ( multiline ) , {
155
157
SIMPLE : 'xyz123' ,
156
158
NON_INTERPOLATED : 'raw text without variable interpolation' ,
157
- MULTILINE : '\nlong text here,\ne.g. a private SSH key\n' ,
159
+ MULTILINE : '\nlong text here, # not-comment \ne.g. a private SSH key\n' ,
158
160
ENV : 'v1' ,
159
161
ENV2 : 'v2' ,
160
162
ENV3 : 'v3' ,
161
163
ENV4 : 'v4' ,
164
+ ENV5 : 'v5' ,
162
165
} )
163
166
164
167
assert . deepEqual (
You can’t perform that action at this time.
0 commit comments