-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from MrDave1999/feature/issue_80
Added support for multi-line values
- Loading branch information
Showing
14 changed files
with
300 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,7 @@ | ||
MYSQL_HOST=mysql | ||
PRIVATE_KEY="[-----BEGIN RSA PRIVATE KEY----- | ||
... | ||
Kh9NV... | ||
... | ||
-----END DSA PRIVATE KEY-----]" | ||
MYSQL_DB=test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
MULTI_UNENDED="THIS | ||
LINE HAS ${VARIABLE_NOT_FOUND} | ||
NO END QUOTE ${VARIABLE_NOT_FOUND_2} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
MULTI_LINE=line | ||
|
||
# | ||
# Double-Quoted | ||
# | ||
MULTI_DOUBLE_QUOTED_1="first ${MULTI_LINE} #a | ||
second ${MULTI_LINE} #b | ||
third ${MULTI_LINE} #c | ||
four ${MULTI_LINE} #d" | ||
|
||
MULTI_DOUBLE_QUOTED_2=" | ||
first ${MULTI_LINE} | ||
second ${MULTI_LINE} | ||
third ${MULTI_LINE} | ||
" | ||
|
||
MULTI_DOUBLE_QUOTED_3="first line | ||
" | ||
MULTI_DOUBLE_QUOTED_4=" | ||
" | ||
MULTI_DOUBLE_QUOTED_5=" | ||
" | ||
|
||
# | ||
# Single-Quoted | ||
# | ||
MULTI_SINGLE_QUOTED_1='first ${MULTI_LINE} #a | ||
second ${MULTI_LINE} #b | ||
third ${MULTI_LINE} #c | ||
four ${MULTI_LINE} #d' | ||
|
||
MULTI_SINGLE_QUOTED_2=' | ||
first ${MULTI_LINE} | ||
second ${MULTI_LINE} | ||
third ${MULTI_LINE} | ||
' | ||
|
||
MULTI_SINGLE_QUOTED_3='first line | ||
' | ||
MULTI_SINGLE_QUOTED_4=' | ||
' | ||
MULTI_SINGLE_QUOTED_5=' | ||
' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
namespace DotEnv.Core.Tests.Parser; | ||
|
||
public partial class EnvParserTests | ||
{ | ||
[TestMethod] | ||
public void Parse_WhenValuesAreOnMultiLines_ShouldGetValuesSeparatedByNewLine() | ||
{ | ||
var parser = new EnvParser().DisableTrimValues(); | ||
|
||
parser.Parse(File.ReadAllText(".env.multi-lines")); | ||
|
||
Assert.AreEqual( | ||
expected: "first line\nsecond line #b\nthird line #c\nfour line #d", | ||
actual: GetEnvironmentVariable("MULTI_DOUBLE_QUOTED_1") | ||
); | ||
Assert.AreEqual( | ||
expected: "\nfirst line\nsecond line\nthird line\n", | ||
actual: GetEnvironmentVariable("MULTI_DOUBLE_QUOTED_2") | ||
); | ||
Assert.AreEqual(expected: "first line\n", actual: GetEnvironmentVariable("MULTI_DOUBLE_QUOTED_3")); | ||
Assert.AreEqual(expected: "\n", actual: GetEnvironmentVariable("MULTI_DOUBLE_QUOTED_4")); | ||
Assert.AreEqual(expected: " \n", actual: GetEnvironmentVariable("MULTI_DOUBLE_QUOTED_5")); | ||
Assert.AreEqual( | ||
expected: "first line\nsecond line #b\nthird line #c\nfour line #d", | ||
actual: GetEnvironmentVariable("MULTI_SINGLE_QUOTED_1") | ||
); | ||
Assert.AreEqual( | ||
expected: "\nfirst line\nsecond line\nthird line\n", | ||
actual: GetEnvironmentVariable("MULTI_SINGLE_QUOTED_2") | ||
); | ||
Assert.AreEqual(expected: "first line\n", actual: GetEnvironmentVariable("MULTI_SINGLE_QUOTED_3")); | ||
Assert.AreEqual(expected: "\n", actual: GetEnvironmentVariable("MULTI_SINGLE_QUOTED_4")); | ||
Assert.AreEqual(expected: " \n", actual: GetEnvironmentVariable("MULTI_SINGLE_QUOTED_5")); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow(@" | ||
MULTI_UNENDED='THIS | ||
LINE HAS | ||
NO END QUOTE | ||
")] | ||
[DataRow(@"MULTI_UNENDED=' | ||
THIS | ||
LINE HAS | ||
NO END QUOTE | ||
")] | ||
[DataRow(@" | ||
MULTI_UNENDED=' | ||
THIS | ||
LINE HAS | ||
NO END QUOTE"" | ||
")] | ||
public void Parse_WhenLineHasNoEndSingleQuote_ShouldThrowParserException(string input) | ||
{ | ||
var parser = new EnvParser(); | ||
|
||
void action() => parser.Parse(input); | ||
|
||
var ex = Assert.ThrowsException<ParserException>(action); | ||
StringAssert.Contains(ex.Message, LineHasNoEndSingleQuoteMessage); | ||
Assert.IsNull(GetEnvironmentVariable("MULTI_UNENDED")); | ||
} | ||
|
||
[TestMethod] | ||
[DataRow(@" | ||
MULTI_UNENDED=""THIS | ||
LINE HAS | ||
NO END QUOTE | ||
")] | ||
[DataRow(@"MULTI_UNENDED="" | ||
THIS | ||
LINE HAS | ||
NO END QUOTE | ||
")] | ||
[DataRow(@" | ||
MULTI_UNENDED="" | ||
THIS | ||
LINE HAS | ||
NO END QUOTE' | ||
")] | ||
public void Parse_WhenLineHasNoEndDoubleQuote_ShouldThrowParserException(string input) | ||
{ | ||
var parser = new EnvParser(); | ||
|
||
void action() => parser.Parse(input); | ||
|
||
var ex = Assert.ThrowsException<ParserException>(action); | ||
StringAssert.Contains(ex.Message, LineHasNoEndDoubleQuoteMessage); | ||
Assert.IsNull(GetEnvironmentVariable("MULTI_UNENDED")); | ||
} | ||
} |
Oops, something went wrong.