hcl/token: Value should unquote string
This commit is contained in:
parent
16ce140272
commit
68e40f3944
@ -136,8 +136,12 @@ func (t Token) Value() interface{} {
|
||||
case IDENT:
|
||||
return t.Text
|
||||
case STRING:
|
||||
// It is wrapped in quotes always
|
||||
return t.Text[1 : len(t.Text)-1]
|
||||
v, err := strconv.Unquote(t.Text)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
return v
|
||||
default:
|
||||
panic(fmt.Sprintf("unimplemented Value for type: %s", t.Type))
|
||||
}
|
||||
|
@ -49,6 +49,7 @@ func TestTokenValue(t *testing.T) {
|
||||
{Token{Type: NUMBER, Text: `42`}, int64(42)},
|
||||
{Token{Type: IDENT, Text: `foo`}, "foo"},
|
||||
{Token{Type: STRING, Text: `"foo"`}, "foo"},
|
||||
{Token{Type: STRING, Text: `"foo\nbar"`}, "foo\nbar"},
|
||||
}
|
||||
|
||||
for _, token := range tokens {
|
||||
|
Loading…
Reference in New Issue
Block a user