summaryrefslogtreecommitdiff
path: root/hclwrite
diff options
context:
space:
mode:
authorAlisdair McDiarmid <alisdair@users.noreply.github.com>2020-05-13 16:02:20 -0400
committerAlisdair McDiarmid <alisdair@users.noreply.github.com>2020-05-13 16:23:21 -0400
commitd58c873a08f1431cba860fb66f572d053837c192 (patch)
tree0aaa6d900bbf3f15c7c7e4c3d6f914f9354bce48 /hclwrite
parentfff0a094cca9609782078bc2c086e6841cdebf45 (diff)
hclwrite: Fix panic for dotted full splat (foo.*)
The following expression caused a panic in hclwrite: a = foo.* This was due to the unusual dotted form of a full splat (where the splat operator is at the end of the expression) being generated with an invalid source range. In the full splat case, the end of the range was uninitialized, which caused the token slice to be empty, and thus the panic. This commit fixes the bug, adds test coverage, and includes some bonus tests for other splat expression cases.
Diffstat (limited to 'hclwrite')
-rw-r--r--hclwrite/parser_test.go216
1 files changed, 216 insertions, 0 deletions
diff --git a/hclwrite/parser_test.go b/hclwrite/parser_test.go
index 9c57c6c..9a4339f 100644
--- a/hclwrite/parser_test.go
+++ b/hclwrite/parser_test.go
@@ -619,6 +619,222 @@ func TestParse(t *testing.T) {
},
},
{
+ "a = foo.*\n",
+ TestTreeNode{
+ Type: "Body",
+ Children: []TestTreeNode{
+ {
+ Type: "Attribute",
+ Children: []TestTreeNode{
+ {
+ Type: "comments",
+ },
+ {
+ Type: "identifier",
+ Val: "a",
+ },
+ {
+ Type: "Tokens",
+ Val: " =",
+ },
+ {
+ Type: "Expression",
+ Children: []TestTreeNode{
+ {
+ Type: "Traversal",
+ Children: []TestTreeNode{
+ {
+ Type: "TraverseName",
+ Children: []TestTreeNode{
+ {
+ Type: "identifier",
+ Val: " foo",
+ },
+ },
+ },
+ },
+ },
+ {
+ Type: "Tokens",
+ Val: ".*",
+ },
+ },
+ },
+ {
+ Type: "comments",
+ },
+ {
+ Type: "Tokens",
+ Val: "\n",
+ },
+ },
+ },
+ },
+ },
+ },
+ {
+ "a = foo.*.bar\n",
+ TestTreeNode{
+ Type: "Body",
+ Children: []TestTreeNode{
+ {
+ Type: "Attribute",
+ Children: []TestTreeNode{
+ {
+ Type: "comments",
+ },
+ {
+ Type: "identifier",
+ Val: "a",
+ },
+ {
+ Type: "Tokens",
+ Val: " =",
+ },
+ {
+ Type: "Expression",
+ Children: []TestTreeNode{
+ {
+ Type: "Traversal",
+ Children: []TestTreeNode{
+ {
+ Type: "TraverseName",
+ Children: []TestTreeNode{
+ {
+ Type: "identifier",
+ Val: " foo",
+ },
+ },
+ },
+ },
+ },
+ {
+ Type: "Tokens",
+ Val: ".*.bar",
+ },
+ },
+ },
+ {
+ Type: "comments",
+ },
+ {
+ Type: "Tokens",
+ Val: "\n",
+ },
+ },
+ },
+ },
+ },
+ },
+ {
+ "a = foo[*]\n",
+ TestTreeNode{
+ Type: "Body",
+ Children: []TestTreeNode{
+ {
+ Type: "Attribute",
+ Children: []TestTreeNode{
+ {
+ Type: "comments",
+ },
+ {
+ Type: "identifier",
+ Val: "a",
+ },
+ {
+ Type: "Tokens",
+ Val: " =",
+ },
+ {
+ Type: "Expression",
+ Children: []TestTreeNode{
+ {
+ Type: "Traversal",
+ Children: []TestTreeNode{
+ {
+ Type: "TraverseName",
+ Children: []TestTreeNode{
+ {
+ Type: "identifier",
+ Val: " foo",
+ },
+ },
+ },
+ },
+ },
+ {
+ Type: "Tokens",
+ Val: "[*]",
+ },
+ },
+ },
+ {
+ Type: "comments",
+ },
+ {
+ Type: "Tokens",
+ Val: "\n",
+ },
+ },
+ },
+ },
+ },
+ },
+ {
+ "a = foo[*].bar\n",
+ TestTreeNode{
+ Type: "Body",
+ Children: []TestTreeNode{
+ {
+ Type: "Attribute",
+ Children: []TestTreeNode{
+ {
+ Type: "comments",
+ },
+ {
+ Type: "identifier",
+ Val: "a",
+ },
+ {
+ Type: "Tokens",
+ Val: " =",
+ },
+ {
+ Type: "Expression",
+ Children: []TestTreeNode{
+ {
+ Type: "Traversal",
+ Children: []TestTreeNode{
+ {
+ Type: "TraverseName",
+ Children: []TestTreeNode{
+ {
+ Type: "identifier",
+ Val: " foo",
+ },
+ },
+ },
+ },
+ },
+ {
+ Type: "Tokens",
+ Val: "[*].bar",
+ },
+ },
+ },
+ {
+ Type: "comments",
+ },
+ {
+ Type: "Tokens",
+ Val: "\n",
+ },
+ },
+ },
+ },
+ },
+ },
+ {
"a = foo[bar]\n",
TestTreeNode{
Type: "Body",