hcl/strconv: more error cases

This commit is contained in:
Mitchell Hashimoto 2015-11-06 23:02:59 -08:00
parent c8f28b7b42
commit 7996653560
2 changed files with 4 additions and 5 deletions

View File

@ -32,7 +32,7 @@ func Unquote(s string) (t string, err error) {
}
// Is it trivial? Avoid allocation.
if !contains(s, '\\') && !contains(s, quote) {
if !contains(s, '\\') && !contains(s, quote) && !contains(s, '$') {
switch quote {
case '"':
return s, nil
@ -56,7 +56,7 @@ func Unquote(s string) (t string, err error) {
// Continue reading until we find the closing brace, copying as-is
braces := 1
for len(s) > 0 {
for len(s) > 0 && braces > 0 {
r, size := utf8.DecodeRuneInString(s)
if r == utf8.RuneError {
return "", ErrSyntax
@ -72,9 +72,6 @@ func Unquote(s string) (t string, err error) {
braces++
case '}':
braces--
if braces == 0 {
break
}
}
}
if braces != 0 {

View File

@ -66,6 +66,8 @@ var misquoted = []string{
"\"\n\"",
"\"\\n\n\"",
"'\n'",
`"${"`,
`"${foo{}"`,
}
func TestUnquote(t *testing.T) {