File tree Expand file tree Collapse file tree 4 files changed +14
-1
lines changed
main/java/io/github/cdimascio/dotenv/internal Expand file tree Collapse file tree 4 files changed +14
-1
lines changed Original file line number Diff line number Diff line change 1919public class DotenvParser {
2020
2121 private static final Pattern WHITE_SPACE_REGEX = Pattern .compile ("^\\ s*$" ); // ^\s*${'$'}
22- private static final Pattern DOTENV_ENTRY_REGEX = Pattern .compile ("^\\ s*([\\ w.\\ -]+)\\ s*(=)\\ s*([^#]*)?\\ s*(#.*)?$" ); // ^\s*([\w.\-]+)\s*(=)\s*([^#]*)?\s*(#.*)?$
22+
23+ // The follow regex matches key values.
24+ // It supports quoted values surrounded by single or double quotes
25+ // - Single quotes: ['][^']*[']
26+ // The above regex snippet matches a value wrapped in single quotes.
27+ // The regex snippet does not match internal single quotes. This is present to allow the trailing comment to include single quotes
28+ // - Double quotes: same logic as single quotes
29+ // It ignore trailing comments
30+ // - Trailing comment: \s*(#.*)?$
31+ // The above snippet ignore spaces, the captures the # and the trailing comment
32+ private static final Pattern DOTENV_ENTRY_REGEX = Pattern .compile ("^\\ s*([\\ w.\\ -]+)\\ s*(=)\\ s*(['][^']*[']|[\" ][^\" ]*[\" ]|[^#]*)?\\ s*(#.*)?$" ); //"^\\s*([\\w.\\-]+)\\s*(=)\\s*([^#]*)?\\s*(#.*)?$"); // ^\s*([\w.\-]+)\s*(=)\s*([^#]*)?\s*(#.*)?$
2333
2434 private final DotenvReader reader ;
2535 private final boolean throwIfMissing ;
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ public class BasicTests {
1616 put ("WITHOUT_VALUE" , "" );
1717 put ("MULTI_LINE" , "hello\\ nworld" );
1818 put ("TRAILING_COMMENT" , "value" );
19+ put ("QUOTED_VALUE" , "iH4>hb_d0#_GN8d]6" );
1920 }};
2021
2122 @ Test (expected = DotenvException .class )
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ MY_TEST_EV2=my test ev 2
44WITHOUT_VALUE =
55MULTI_LINE = hello\nworld
66TRAILING_COMMENT = value # comment
7+ QUOTED_VALUE = " iH4>hb_d0#_GN8d]6" # comment "test"
78
89# # Malformed EV!
910MY_TEST_EV3
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ MY_TEST_EV2=my test ev 2
44WITHOUT_VALUE=
55MULTI_LINE=hello\nworld
66TRAILING_COMMENT=value # comment
7+ QUOTED_VALUE="iH4>hb_d0#_GN8d]6" # comment "test"
78
89## Malformed EV!
910MY_TEST_EV3
You can’t perform that action at this time.
0 commit comments