Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when loading env file (--env-file), env variable will not be loaded if preceding 'blank' line contains space(s) or tab(s) #56686

Open
jlchristi opened this issue Jan 21, 2025 · 1 comment

Comments

@jlchristi
Copy link

Version

v22.11.0

Platform

Linux abu 4.4.0-22621-Microsoft #3672-Microsoft Fri Jan 01 08:00:00 PST 2016 x86_64 x86_64 x86_64 GNU/Linux

Subsystem

Ubuntu-22.04

What steps will reproduce the bug?

$ cat testenv
# the next line is an empty line

EMPTY_LINE='empty line'
# the next line contains spaces

SPACES_LINE='spaces line'
# the next line contains tabs

TAB_LINE='tab line'

$ hexdump -C testenv
00000000  23 20 74 68 65 20 6e 65  78 74 20 6c 69 6e 65 20  |# the next line |
00000010  69 73 20 61 6e 20 65 6d  70 74 79 20 6c 69 6e 65  |is an empty line|
00000020  0a 0a 45 4d 50 54 59 5f  4c 49 4e 45 3d 27 65 6d  |..EMPTY_LINE='em|
00000030  70 74 79 20 6c 69 6e 65  27 0a 23 20 74 68 65 20  |pty line'.# the |
00000040  6e 65 78 74 20 6c 69 6e  65 20 63 6f 6e 74 61 69  |next line contai|
00000050  6e 73 20 73 70 61 63 65  73 0a 20 20 20 0a 53 50  |ns spaces.   .SP|
00000060  41 43 45 53 5f 4c 49 4e  45 3d 27 73 70 61 63 65  |ACES_LINE='space|
00000070  73 20 6c 69 6e 65 27 0a  23 20 74 68 65 20 6e 65  |s line'.# the ne|
00000080  78 74 20 6c 69 6e 65 20  63 6f 6e 74 61 69 6e 73  |xt line contains|
00000090  20 74 61 62 73 0a 09 09  0a 54 41 42 5f 4c 49 4e  | tabs....TAB_LIN|
000000a0  45 3d 27 74 61 62 20 6c  69 6e 65 27 0a           |E='tab line'.|
000000ad

$ node --env-file=testenv -e 'console.log(`EMPTY_LINE: ${process.env.EMPTY_LINE}\nSPACES_LINE: ${process.env.SPACE_LINE}\nTAB_LINE: ${process.env.TAB_LINE}`);'
EMPTY_LINE: empty line
SPACES_LINE: undefined
TAB_LINE: undefined

$

How often does it reproduce? Is there a required condition?

Always happens. If the env file has a 'blank' line containing space(s) or tab(s), the environment variable defined on the next line will not be loaded at runtime.

What is the expected behavior? Why is that the expected behavior?

It is expected that blank lines (empty, spaces, tabs, whitespace) will be ignored when process the env file.

What do you see instead?

'blank' lines containing whitespace prevent the env variable declared on the following line from being loaded.

Additional information

No response

@jlchristi
Copy link
Author

Just noticed there is a misprint in the test (${process.env.SPACE_LINE}). It should be

$ node --env-file=testenv -e 'console.log(`EMPTY_LINE: ${process.env.EMPTY_LINE}\nSPACES_LINE: ${process.env.SPACES_LINE}\nTAB_LINE: ${pro
cess.env.TAB_LINE}`);'

but it still gives the same results...

EMPTY_LINE: empty line
SPACES_LINE: undefined
TAB_LINE: undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant