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:
|
case IDENT:
|
||||||
return t.Text
|
return t.Text
|
||||||
case STRING:
|
case STRING:
|
||||||
// It is wrapped in quotes always
|
v, err := strconv.Unquote(t.Text)
|
||||||
return t.Text[1 : len(t.Text)-1]
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
return v
|
||||||
default:
|
default:
|
||||||
panic(fmt.Sprintf("unimplemented Value for type: %s", t.Type))
|
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: NUMBER, Text: `42`}, int64(42)},
|
||||||
{Token{Type: IDENT, Text: `foo`}, "foo"},
|
{Token{Type: IDENT, Text: `foo`}, "foo"},
|
||||||
{Token{Type: STRING, Text: `"foo"`}, "foo"},
|
{Token{Type: STRING, Text: `"foo"`}, "foo"},
|
||||||
|
{Token{Type: STRING, Text: `"foo\nbar"`}, "foo\nbar"},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, token := range tokens {
|
for _, token := range tokens {
|
||||||
|
Loading…
Reference in New Issue
Block a user