mirror of https://github.com/joho/godotenv.git
fix: if a line contains multiple # characters, there will be issues w… (#238)
* fix: if a line contains multiple # characters, there will be issues when traversing from back to front * fix: typomain v1.6.0-pre.2
parent
a7f6c4c583
commit
3a7a190201
|
@ -1,4 +1,7 @@
|
||||||
# Full line comment
|
# Full line comment
|
||||||
|
qux=thud # fred # other
|
||||||
|
thud=fred#qux # other
|
||||||
|
fred=qux#baz # other # more
|
||||||
foo=bar # baz
|
foo=bar # baz
|
||||||
bar=foo#baz
|
bar=foo#baz
|
||||||
baz="foo"#bar
|
baz="foo"#bar
|
||||||
|
|
|
@ -477,6 +477,9 @@ func TestErrorParsing(t *testing.T) {
|
||||||
func TestComments(t *testing.T) {
|
func TestComments(t *testing.T) {
|
||||||
envFileName := "fixtures/comments.env"
|
envFileName := "fixtures/comments.env"
|
||||||
expectedValues := map[string]string{
|
expectedValues := map[string]string{
|
||||||
|
"qux": "thud",
|
||||||
|
"thud": "fred#qux",
|
||||||
|
"fred": "qux#baz",
|
||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"bar": "foo#baz",
|
"bar": "foo#baz",
|
||||||
"baz": "foo",
|
"baz": "foo",
|
||||||
|
|
|
@ -143,9 +143,9 @@ func extractVarValue(src []byte, vars map[string]string) (value string, rest []b
|
||||||
}
|
}
|
||||||
|
|
||||||
// Work backwards to check if the line ends in whitespace then
|
// Work backwards to check if the line ends in whitespace then
|
||||||
// a comment (ie asdasd # some comment)
|
// a comment, ie: foo=bar # baz # other
|
||||||
for i := endOfVar - 1; i >= 0; i-- {
|
for i := 0; i < endOfVar; i++ {
|
||||||
if line[i] == charComment && i > 0 {
|
if line[i] == charComment && i < endOfVar {
|
||||||
if isSpace(line[i-1]) {
|
if isSpace(line[i-1]) {
|
||||||
endOfVar = i
|
endOfVar = i
|
||||||
break
|
break
|
||||||
|
|
Loading…
Reference in New Issue