From c190e414039befc5edfbea0eb7c82c2975dac6cd Mon Sep 17 00:00:00 2001 From: James Nugent Date: Tue, 24 Nov 2015 15:13:07 +0200 Subject: [PATCH] Fix scanning of identifiers of the form 'map.key' This is used in `.tfvars` files for Terraform in order to allow overriding values in maps, for example: map.key1 = "Value" map.key2 = "OtherValue" --- decoder_test.go | 9 +++++++++ hcl/scanner/scanner.go | 2 +- test-fixtures/tfvars.hcl | 3 +++ 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 test-fixtures/tfvars.hcl diff --git a/decoder_test.go b/decoder_test.go index 116b400..9ff4243 100644 --- a/decoder_test.go +++ b/decoder_test.go @@ -43,6 +43,15 @@ func TestDecode_interface(t *testing.T) { }, }, }, + { + "tfvars.hcl", + false, + map[string]interface{}{ + "regularvar": "Should work", + "map.key1": "Value", + "map.key2": "Other value", + }, + }, { "escape.hcl", false, diff --git a/hcl/scanner/scanner.go b/hcl/scanner/scanner.go index 306c899..a46cfdc 100644 --- a/hcl/scanner/scanner.go +++ b/hcl/scanner/scanner.go @@ -516,7 +516,7 @@ func (s *Scanner) scanDigits(ch rune, base, n int) rune { func (s *Scanner) scanIdentifier() string { offs := s.srcPos.Offset - s.lastCharLen ch := s.next() - for isLetter(ch) || isDigit(ch) || ch == '-' { + for isLetter(ch) || isDigit(ch) || ch == '-' || ch == '.' { ch = s.next() } diff --git a/test-fixtures/tfvars.hcl b/test-fixtures/tfvars.hcl new file mode 100644 index 0000000..5f623e0 --- /dev/null +++ b/test-fixtures/tfvars.hcl @@ -0,0 +1,3 @@ +regularvar = "Should work" +map.key1 = "Value" +map.key2 = "Other value"