escape some other bash-y special chars ($!)

This commit is contained in:
Alex Quick
2017-07-16 18:31:51 -04:00
parent 88e7c8bd35
commit 5d289f4405
2 changed files with 14 additions and 6 deletions

View File

@ -24,6 +24,8 @@ import (
"strings"
)
const doubleQuoteSpecialChars = "\\\n\r\"!$`"
// Load will read your env file(s) and load them into ENV for this process.
//
// Call this function as close as possible to the start of your program (ideally in main)
@ -297,9 +299,15 @@ func isIgnoredLine(line string) bool {
}
func doubleQuoteEscape(line string) string {
line = strings.Replace(line, `\`, `\\`, -1)
line = strings.Replace(line, "\n", `\n`, -1)
line = strings.Replace(line, "\r", `\r`, -1)
line = strings.Replace(line, `"`, `\"`, -1)
for _, c := range doubleQuoteSpecialChars {
toReplace := "\\" + string(c)
if c == '\n' {
toReplace = `\n`
}
if c == '\r' {
toReplace = `\r`
}
line = strings.Replace(line, string(c), toReplace, -1)
}
return line
}