diff --git a/hcl/token/token.go b/hcl/token/token.go index 32015a2..c414fa4 100644 --- a/hcl/token/token.go +++ b/hcl/token/token.go @@ -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)) } diff --git a/hcl/token/token_test.go b/hcl/token/token_test.go index 014e76c..7b23788 100644 --- a/hcl/token/token_test.go +++ b/hcl/token/token_test.go @@ -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 {