Skip to content
This repository has been archived by the owner on Feb 7, 2023. It is now read-only.

Commit

Permalink
fix: retain inline comments
Browse files Browse the repository at this point in the history
  • Loading branch information
decentral1se committed Jul 31, 2021
1 parent d6ee687 commit b031ea1
Showing 1 changed file with 0 additions and 23 deletions.
23 changes: 0 additions & 23 deletions godotenv.go
Expand Up @@ -222,29 +222,6 @@ func parseLine(line string, envMap map[string]string) (key string, value string,
return
}

// ditch the comments (but keep quoted hashes)
if strings.Contains(line, "#") {
segmentsBetweenHashes := strings.Split(line, "#")
quotesAreOpen := false
var segmentsToKeep []string
for _, segment := range segmentsBetweenHashes {
if strings.Count(segment, "\"") == 1 || strings.Count(segment, "'") == 1 {
if quotesAreOpen {
quotesAreOpen = false
segmentsToKeep = append(segmentsToKeep, segment)
} else {
quotesAreOpen = true
}
}

if len(segmentsToKeep) == 0 || quotesAreOpen {
segmentsToKeep = append(segmentsToKeep, segment)
}
}

line = strings.Join(segmentsToKeep, "#")
}

firstEquals := strings.Index(line, "=")
firstColon := strings.Index(line, ":")
splitString := strings.SplitN(line, "=", 2)
Expand Down

0 comments on commit b031ea1

Please sign in to comment.