Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
refactor: apply comment
  • Loading branch information
rayark1 committed Mar 14, 2025
commit 12105d97e5f92f5eef700ef12f8efe83996198ca
2 changes: 1 addition & 1 deletion benchmark/fixtures/valid.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BASIC=basic

# previous line intentionally left blank
AFTER_LINE=after_line
A=B=C
A="B=C"
EMPTY=
EMPTY_SINGLE_QUOTES=''
EMPTY_DOUBLE_QUOTES=""
Expand Down
18 changes: 7 additions & 11 deletions src/node_dotenv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ void Dotenv::ParseContent(const std::string_view input) {
if (newline != std::string_view::npos) {
content.remove_prefix(newline + 1);
} else {
content.remove_prefix(content.size());
content = {};
}
continue;
Comment thread
anonrig marked this conversation as resolved.
}
Expand Down Expand Up @@ -203,7 +203,7 @@ void Dotenv::ParseContent(const std::string_view input) {
if (newline != std::string_view::npos) {
content.remove_prefix(newline + 1);
} else {
content.remove_prefix(content.size());
content = {};
}
continue;
}
Expand Down Expand Up @@ -236,7 +236,7 @@ void Dotenv::ParseContent(const std::string_view input) {
if (newline != std::string_view::npos) {
content.remove_prefix(newline + 1);
} else {
content.remove_prefix(content.size());
content = {};
}
continue;
Comment thread
anonrig marked this conversation as resolved.
}
Expand All @@ -254,8 +254,7 @@ void Dotenv::ParseContent(const std::string_view input) {
if (hash_character != std::string_view::npos) {
value = content.substr(0, hash_character);
}
value = trim_spaces(value);
store_.insert_or_assign(std::string(key), value);
store_.insert_or_assign(std::string(key), trim_spaces(value));
content.remove_prefix(newline + 1);
} else {
// In case the last line is a single key/value pair
Expand All @@ -265,14 +264,11 @@ void Dotenv::ParseContent(const std::string_view input) {
if (hash_char != std::string_view::npos) {
value = content.substr(0, hash_char);
}
value = trim_spaces(value);

store_.insert_or_assign(std::string(key), value);
content.remove_prefix(content.size());
store_.insert_or_assign(std::string(key), trim_spaces(value));
content = {};
}

value = trim_spaces(value);
store_.insert_or_assign(std::string(key), value);
store_.insert_or_assign(std::string(key), trim_spaces(value));
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/dotenv/valid.env
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BASIC=basic

# previous line intentionally left blank
AFTER_LINE=after_line
A=B=C
A="B=C"
EMPTY=
EMPTY_SINGLE_QUOTES=''
EMPTY_DOUBLE_QUOTES=""
Expand Down
Loading