fix panic with `"` as the value

pull/34/head
Alex Quick 2017-07-16 18:43:49 -04:00
parent 6f30f0c011
commit a905e99577
2 changed files with 6 additions and 2 deletions

View File

@ -228,8 +228,8 @@ func parseValue(value string) string {
// trim
value = strings.Trim(value, " ")
// check if we've got quoted values
if value != "" {
// check if we've got quoted values or possible escapes
if len(value) > 1 {
first := string(value[0:1])
last := string(value[len(value)-1:])
if first == last && strings.ContainsAny(first, `"'`) {

View File

@ -252,6 +252,10 @@ func TestParsing(t *testing.T) {
parseAndCompare(t, `FOO="bar\\\n\ b\az"`, "FOO", "bar\\\n baz")
parseAndCompare(t, `FOO="bar\\r\ b\az"`, "FOO", "bar\\r baz")
parseAndCompare(t, `="value"`, "", "value")
parseAndCompare(t, `KEY="`, "KEY", "\"")
parseAndCompare(t, `KEY="value`, "KEY", "\"value")
// it 'throws an error if line format is incorrect' do
// expect{env('lol$wut')}.to raise_error(Dotenv::FormatError)
badlyFormattedLine := "lol$wut"