Allow escaping quotes in HCL string [GH-14]

This commit is contained in:
Mitchell Hashimoto 2014-10-10 16:07:25 -07:00
parent 09d7815762
commit 764b0ad3c0
3 changed files with 21 additions and 0 deletions

View File

@ -43,6 +43,13 @@ func TestDecode_interface(t *testing.T) {
},
},
},
{
"escape.hcl",
false,
map[string]interface{}{
"foo": "bar\"baz",
},
},
{
"multiline_bad.hcl",
false,

View File

@ -357,6 +357,19 @@ func (x *hclLex) lexString(yylval *hclSymType) int {
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 braces == 0 && c == '$' && x.peek() == '{' {
braces += 1

1
test-fixtures/escape.hcl Normal file
View File

@ -0,0 +1 @@
foo = "bar\"baz"