summaryrefslogtreecommitdiff
path: root/hclsyntax/parser_test.go
diff options
context:
space:
mode:
authorAlisdair McDiarmid <alisdair@users.noreply.github.com>2021-05-04 11:57:55 -0400
committerAlisdair McDiarmid <alisdair@users.noreply.github.com>2021-05-04 11:57:55 -0400
commitad6a17cba6381eebff346ab26689e9d02a75f2e0 (patch)
treefdff4d5af8e104e653eaaa1b3111b912e72c3206 /hclsyntax/parser_test.go
parentf60199196cd4b7cd16eef77d76b7c92a5d37020e (diff)
Fix parseQuotedStringLiteral zero end range
If a block label had an invalid quoted string literal, the parser would previously create label ranges with uninitialized `End` values. For Terraform, this would eventually percolate into invalid diagnostic output due to the assumption that the end of a range is always greater than or equal to the start. This commit addresses this by using the terminating token's position as the end of the range, even if it's not a closing quote.
Diffstat (limited to 'hclsyntax/parser_test.go')
-rw-r--r--hclsyntax/parser_test.go58
1 files changed, 58 insertions, 0 deletions
diff --git a/hclsyntax/parser_test.go b/hclsyntax/parser_test.go
index 45b5645..8b083da 100644
--- a/hclsyntax/parser_test.go
+++ b/hclsyntax/parser_test.go
@@ -2484,6 +2484,64 @@ block "valid" {}
},
},
},
+ {
+ `block "unterminated_string "name" {}`,
+ 2, // "Invalid string literal" and "Invalid block definition"
+ &Body{
+ Attributes: Attributes{},
+ Blocks: Blocks{
+ &Block{
+ Type: "block",
+ Labels: []string{"unterminated_string ", "name", " {}"},
+ Body: &Body{
+ SrcRange: hcl.Range{
+ Start: hcl.Pos{Line: 1, Column: 1, Byte: 0},
+ End: hcl.Pos{Line: 1, Column: 6, Byte: 5},
+ },
+ EndRange: hcl.Range{
+ Start: hcl.Pos{Line: 1, Column: 1, Byte: 0},
+ End: hcl.Pos{Line: 1, Column: 6, Byte: 5},
+ },
+ },
+
+ TypeRange: hcl.Range{
+ Start: hcl.Pos{Line: 1, Column: 1, Byte: 0},
+ End: hcl.Pos{Line: 1, Column: 6, Byte: 5},
+ },
+ LabelRanges: []hcl.Range{
+ {
+ Start: hcl.Pos{Line: 1, Column: 7, Byte: 6},
+ End: hcl.Pos{Line: 1, Column: 29, Byte: 28},
+ },
+ {
+ Start: hcl.Pos{Line: 1, Column: 29, Byte: 28},
+ End: hcl.Pos{Line: 1, Column: 33, Byte: 32},
+ },
+ {
+ Start: hcl.Pos{Line: 1, Column: 33, Byte: 32},
+ End: hcl.Pos{Line: 1, Column: 37, Byte: 36},
+ },
+ },
+ OpenBraceRange: hcl.Range{
+ Start: hcl.Pos{Line: 1, Column: 1, Byte: 0},
+ End: hcl.Pos{Line: 1, Column: 6, Byte: 5},
+ },
+ CloseBraceRange: hcl.Range{
+ Start: hcl.Pos{Line: 1, Column: 1, Byte: 0},
+ End: hcl.Pos{Line: 1, Column: 6, Byte: 5},
+ },
+ },
+ },
+ SrcRange: hcl.Range{
+ Start: hcl.Pos{Line: 1, Column: 1, Byte: 0},
+ End: hcl.Pos{Line: 1, Column: 37, Byte: 36},
+ },
+ EndRange: hcl.Range{
+ Start: hcl.Pos{Line: 1, Column: 37, Byte: 36},
+ End: hcl.Pos{Line: 1, Column: 37, Byte: 36},
+ },
+ },
+ },
}
for _, test := range tests {