Allow escaping quotes in HCL string [GH-14]
This commit is contained in:
parent
09d7815762
commit
764b0ad3c0
@ -43,6 +43,13 @@ func TestDecode_interface(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"escape.hcl",
|
||||||
|
false,
|
||||||
|
map[string]interface{}{
|
||||||
|
"foo": "bar\"baz",
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"multiline_bad.hcl",
|
"multiline_bad.hcl",
|
||||||
false,
|
false,
|
||||||
|
13
hcl/lex.go
13
hcl/lex.go
@ -357,6 +357,19 @@ func (x *hclLex) lexString(yylval *hclSymType) int {
|
|||||||
return lexEOF
|
return lexEOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we're escaping a quote, then escape the quote
|
||||||
|
if c == '\\' {
|
||||||
|
n := x.next()
|
||||||
|
switch n {
|
||||||
|
case '"':
|
||||||
|
c = n
|
||||||
|
case 'n':
|
||||||
|
c = '\n'
|
||||||
|
default:
|
||||||
|
x.backup()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// If we're starting into variable, mark it
|
// If we're starting into variable, mark it
|
||||||
if braces == 0 && c == '$' && x.peek() == '{' {
|
if braces == 0 && c == '$' && x.peek() == '{' {
|
||||||
braces += 1
|
braces += 1
|
||||||
|
1
test-fixtures/escape.hcl
Normal file
1
test-fixtures/escape.hcl
Normal file
@ -0,0 +1 @@
|
|||||||
|
foo = "bar\"baz"
|
Loading…
Reference in New Issue
Block a user