Skip to content
This repository was archived by the owner on Jan 12, 2022. It is now read-only.

Commit a905e99

Browse files
committed
fix panic with " as the value
1 parent 6f30f0c commit a905e99

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

godotenv.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ func parseValue(value string) string {
228228
// trim
229229
value = strings.Trim(value, " ")
230230

231-
// check if we've got quoted values
232-
if value != "" {
231+
// check if we've got quoted values or possible escapes
232+
if len(value) > 1 {
233233
first := string(value[0:1])
234234
last := string(value[len(value)-1:])
235235
if first == last && strings.ContainsAny(first, `"'`) {

godotenv_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,10 @@ func TestParsing(t *testing.T) {
252252
parseAndCompare(t, `FOO="bar\\\n\ b\az"`, "FOO", "bar\\\n baz")
253253
parseAndCompare(t, `FOO="bar\\r\ b\az"`, "FOO", "bar\\r baz")
254254

255+
parseAndCompare(t, `="value"`, "", "value")
256+
parseAndCompare(t, `KEY="`, "KEY", "\"")
257+
parseAndCompare(t, `KEY="value`, "KEY", "\"value")
258+
255259
// it 'throws an error if line format is incorrect' do
256260
// expect{env('lol$wut')}.to raise_error(Dotenv::FormatError)
257261
badlyFormattedLine := "lol$wut"

0 commit comments

Comments
 (0)