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

Support trailing comments #38

Merged
merged 2 commits into from
Nov 23, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
public class DotenvParser {

private static final Pattern WHITE_SPACE_REGEX = Pattern.compile("^\\s*$"); // ^\s*${'$'}
private static final Pattern DOTENV_ENTRY_REGEX = Pattern.compile("^\\s*([\\w.\\-]+)\\s*(=)\\s*(.*)?\\s*$"); // ^\s*([\w.\-]+)\s*(=)\s*(.*)?\s*$
private static final Pattern DOTENV_ENTRY_REGEX = Pattern.compile("^\\s*([\\w.\\-]+)\\s*(=)\\s*([^#]*)?\\s*(#.*)?$"); // ^\s*([\w.\-]+)\s*(=)\s*([^#]*)?\s*(#.*)?$

private final DotenvReader reader;
private final boolean throwIfMissing;
Expand Down
1 change: 1 addition & 0 deletions src/test/java/tests/BasicTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class BasicTests {
put("MY_TEST_EV2", "my test ev 2");
put("WITHOUT_VALUE", "");
put("MULTI_LINE", "hello\\nworld");
put("TRAILING_COMMENT", "value");
}};

@Test(expected = DotenvException.class)
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/.env
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ MY_TEST_EV1=my test ev 1
MY_TEST_EV2=my test ev 2
WITHOUT_VALUE=
MULTI_LINE=hello\nworld
TRAILING_COMMENT=value # comment

## Malformed EV!
MY_TEST_EV3
Expand Down
1 change: 1 addition & 0 deletions src/test/resources/env
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ MY_TEST_EV1=my test ev 1
MY_TEST_EV2=my test ev 2
WITHOUT_VALUE=
MULTI_LINE=hello\nworld
TRAILING_COMMENT=value # comment

## Malformed EV!
MY_TEST_EV3