Skip to content

Crashes when --env-file=file does not have a newline at the end #55925

Closed
@vignedev

Description

@vignedev

Version

v22.10.0

Platform

Linux vigbox 6.11.3-arch1-1 #1 SMP PREEMPT_DYNAMIC Thu, 10 Oct 2024 20:11:06 +0000 x86_64 GNU/Linux

Subsystem

No response

What steps will reproduce the bug?

  1. Create a file with a quoted value and no new line at the end (eg. printf 'API_KEY="inaaa"' > .env)
  2. Run node --env-file=.env

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

Always, if the --env-file file has no newline at the end, and if the value before it is surrounded with quotes.

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

For node to not crash, and for it to parse the value into process.env.

What do you see instead?

$ node --version
v22.10.0

$ printf 'API_KEY="inaaa"' > .env

$ xxd .env # just to make sure there is no newline at the end
00000000: 4150 495f 4b45 593d 2269 6e61 6161 22    API_KEY="inaaa"

$ node --env-file=.env
/usr/include/c++/14.2.1/string_view:297: constexpr void std::basic_string_view<_CharT, _Traits>::remove_prefix(size_type) [with _CharT = char; _Traits = std::char_traits<char>; size_type = long unsigned int]: Assertion 'this->_M_len >= __n' failed.
Aborted (core dumped)

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    dotenvIssues and PRs related to .env file parsing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions