File tree 4 files changed +14
-1
lines changed
main/java/io/github/cdimascio/dotenv/internal
4 files changed +14
-1
lines changed Original file line number Diff line number Diff line change 19
19
public class DotenvParser {
20
20
21
21
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*(#.*)?$
23
33
24
34
private final DotenvReader reader ;
25
35
private final boolean throwIfMissing ;
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ public class BasicTests {
16
16
put ("WITHOUT_VALUE" , "" );
17
17
put ("MULTI_LINE" , "hello\\ nworld" );
18
18
put ("TRAILING_COMMENT" , "value" );
19
+ put ("QUOTED_VALUE" , "iH4>hb_d0#_GN8d]6" );
19
20
}};
20
21
21
22
@ 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
4
4
WITHOUT_VALUE =
5
5
MULTI_LINE = hello\nworld
6
6
TRAILING_COMMENT = value # comment
7
+ QUOTED_VALUE = "iH4>hb_d0#_GN8d]6" # comment "test"
7
8
8
9
# # Malformed EV!
9
10
MY_TEST_EV3
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ MY_TEST_EV2=my test ev 2
4
4
WITHOUT_VALUE=
5
5
MULTI_LINE=hello\nworld
6
6
TRAILING_COMMENT=value # comment
7
+ QUOTED_VALUE="iH4>hb_d0#_GN8d]6" # comment "test"
7
8
8
9
## Malformed EV!
9
10
MY_TEST_EV3
You can’t perform that action at this time.
0 commit comments