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
src: updates functionality for .env files #51130
base: main
Are you sure you want to change the base?
Conversation
Adds heredocs, string interpolation, triple quotes, control codes. Updates for backticks, single and double quotes.
|
Review requested:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the PR description to include what features we are adding with 1600 lines of code? Depending on the cost of implementation that feature we should trim these lines.
IMHO: 1600 lines for an env file parser is too much.
| }; | ||
| class EnvStream { | ||
| size_t index_ = 0; | ||
| std::string* data_ = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we have a string pointer, but not std::string_view?
| @@ -32,6 +35,170 @@ class Dotenv { | |||
|
|
|||
| } // namespace node | |||
|
|
|||
| namespace cppnv { | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should move this inside node namespace.
| return own_buffer != nullptr; | ||
| } | ||
|
|
||
| void set_own_buffer(std::string* buff) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lack of documentation on these functions make it really hard to review/approve this PR
| return ret; | ||
| } | ||
|
|
||
| bool cppnv::EnvStream::good() const { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The naming convention makes it really hard to understand what this function does.
| return end_of_stream_key; | ||
| } | ||
|
|
||
| int EnvReader::get_white_space_offset_left(const std::string* value, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use std::string_view instead of std::string* in everywhere.
Updated
.env parser
Notable Changes
All previous features including backtick quotes work the same. It passes all previous tests and I've add quite a few more. Runs quickly as I minimalized the amount of allocations by reusing a string buffer and only copying when I need to. I avoided string split and trim as well to avoid more allocs. On average in debug mode on my machine it took about 14ms to run. Mileage may vary and I know I can squeeze a little more out of it if needed.
note Because of my love of granular checkpoint commits and a misunderstanding of the docs when it came to messages (subsystems vs update,fix) I deleted my original fork and just created a new one instead of wrestling with a huge rebase that could unlink me from the upstream. This is the same code as before.
Link to new tests
Context: The current env parser doesn't have full .env compatibility. It lacks heredocs and interpolation. After a conversation with @anonrig I decided to pursue adding this to node.