Commit Graph

422 Commits

Author SHA1 Message Date
Tim
ef28deed85 Added hcl to json example for nested objects (#36)
It was unclear how nested object example in hcl would map to json.
README now updated to include an example of the son equivalent
to a hcl nested object.
2016-09-02 11:46:43 -05:00
James Nugent
9edfb078e1 Merge pull request #121 from hashicorp/filter-skip-nil-item
Skip nil items during filtering
2016-09-02 11:32:56 -05:00
Mitchell Hashimoto
2fd69cb0a5 json: interpolations have to be escaped
At some point we ignored the " in interpolations. We do this for HCL and
it is correct but this is invalid JSON syntax and for JSON we've always
had the stance that we have to escape them.
2016-09-02 11:31:47 -05:00
James Nugent
05be7a778d Merge pull request #146 from hashicorp/b-comment
hcl/scanner: single line '//' commments verify second '/'
2016-09-02 11:27:27 -05:00
Mitchell Hashimoto
9250907631
hcl/scanner: single line '//' commments verify second '/'
The way the scanner works '/ foo' was actually valid comment syntax.
This obviously is not what we want. This modifies the scanner to verify
that '//' comments in fact have the second '/'.
2016-09-01 19:50:55 -07:00
Mitchell Hashimoto
baeb59c710
hcl/parser: test case for error in "10kb"
https://github.com/hashicorp/terraform/issues/3287#issuecomment-195779840
2016-08-22 14:41:45 -07:00
Mitchell Hashimoto
bc40da04e8 Merge pull request #143 from hashicorp/b-invalid-object-value
Fix panic when decoding invalid value structure into struct
2016-08-22 12:37:30 -04:00
Mitchell Hashimoto
40a9504600
fix panic when decoding invalid value structure into struct
When decoding an object into a struct where the object structure doesn't
match the Go struct structure, the case tested here would panic. This
introduces additional checks to guard against the edge case being hit to
avoid the panic.

The specific checks being added are: if an item being decoded into a
struct is a literal type, the item to be decoded must be non-nil in
order to use it. This isn't super clear and to be honest I also don't
fully understand it but this fixes the problem without introducing any
more test failures and without significant code complexity.
2016-08-21 23:44:35 -07:00
James Nugent
d8c773c4cb Merge pull request #138 from hashicorp/multiline-strings
Support multiline string literals in HCL
2016-07-11 17:17:52 -06:00
James Nugent
a55c206bd0 Support multiline string literals in HCL
This allows multiline strings to be parsed in order to make HIL
interpolations nicer in Terraform:

```
my_complex_thing = "${merge(var.list1,
                            var.list2,
                            var.list3)}"
```
2016-07-11 14:33:17 -06:00
Paul Hinze
364df43084 Merge pull request #137 from hashicorp/f-list-of-maps
hcl/parser: Support lists of objects
2016-07-08 09:13:38 -05:00
James Nugent
5c900ca702 Add test for list of objects in printer 2016-07-08 13:25:14 +01:00
James Nugent
c30e0cdccf Update documentation for lists of maps 2016-07-08 12:04:41 +01:00
James Nugent
d7ee01d2a7 Merge pull request #135 from hashicorp/b-null
hcl/scanner: handle \"\\0 input properly
2016-07-08 11:51:59 +01:00
Paul Hinze
92237bfa68
hcl/parser: Support lists of objects
a.k.a lists of maps

Implementation was pretty straightforward - I had to tweak the `needsComma`
handling since it was stuck inside literal parsing. It happens out front
now. I also promoted the `assign_deep.hcl` parser test to a decoder
test that passes, since it was testing for an error to occur but now it
works! :)

Additionally we make ObjectLists support being comma-delimited, which
enables maps to defined inline like `{one = 1, two = 2}`.

Refs https://github.com/hashicorp/terraform/issues/7142
2016-07-06 13:01:52 -05:00
James Nugent
61f5143284 Merge pull request #134 from hashicorp/b-fuzz
Fix parser bugs found via fuzzing from GH-128
2016-06-24 15:12:30 +03:00
Mitchell Hashimoto
5b7dbf7eef Merge pull request #117 from dcarley/fmt_docs_write
hcl/fmtcmd: Clarify docs for Options.Diff
2016-06-21 13:42:41 -07:00
Mitchell Hashimoto
eb82ad4309 Merge pull request #120 from mirdhyn/ignored-tag
Ignore field when tag is "-" when decoding structs
2016-06-21 13:42:14 -07:00
Mitchell Hashimoto
66b2aabe46
hcl/scanner: more comments 2016-06-21 13:39:12 -07:00
Mitchell Hashimoto
a6c7514d8d
hcl/scanner: handle \"\\0 input properly 2016-06-21 13:38:25 -07:00
Mitchell Hashimoto
c9b6178f09
hcl/parser: remove spew 2016-06-21 13:26:05 -07:00
Mitchell Hashimoto
cb3a023ffc
add final fuzz case for GH-128 2016-06-21 13:23:11 -07:00
Mitchell Hashimoto
50042432b0
hcl/parser: fix broken parsing of: "v=/\n[," 2016-06-21 13:21:48 -07:00
Mitchell Hashimoto
6816a5c3fb
fix panic on decode of "t=0t d{}" 2016-06-21 13:18:51 -07:00
Mitchell Hashimoto
352bb4b5e3
hcl/parser: don't allow objects with no keys 2016-06-21 13:07:06 -07:00
Mitchell Hashimoto
685b5f7416
json: verify that objects have keys [GH-128] 2016-06-21 12:57:45 -07:00
James Nugent
da48636430 Merge pull request #133 from hashicorp/json-null-string
Fix bug with unquoting null from JSON-encoded HCL
2016-06-20 19:04:52 +02:00
James Nugent
39143f46f8 Fix bug with unquoting null from JSON-encoded HCL
Fixes hashicorp/terraform#6774.
2016-06-20 20:02:34 +03:00
Paul Hinze
aa7699b7b6 Merge pull request #132 from hashicorp/b-remove-bc-double-quote-behavior
Remove BC escaped double quote behavior
2016-06-16 23:00:17 +02:00
Paul Hinze
2fb7c957a4
Remove BC escaped double quote behavior
When we switched to the current edition of the HCL parser, we
inadvertently broke some undocumented behavior where users could
successfully used escaped double quotes in a nested interpolation like
this:

    foo = "${somefunc(\"somearg\")}"

The proper syntax here is:

    foo = "${somefunc("somearg")}"

Because once you are inside the interpolation braces, the "quoting
context" is different.

At the time, while we didn't like the fact that the non-standard syntax
was in the wild, we didn't want to break BC, so we treated it as a bug
and fixed it in #62.

Now that we are at the moment of a major Terraform release, we can yank
the BC compatible behavior, which fixes a currently broken use case -
there is no way to express strings with double quotes in them from
inside interpolation braces.

    foo = "${somefunc("\"inquotes\"")}"

After merge and a dep upgrade, this will take care of
https://github.com/hashicorp/terraform/issues/5550
2016-06-16 12:43:37 -05:00
Paul Hinze
d7400db714 Merge pull request #125 from hashicorp/b-escapes
strconv: Fix escaped backslashes \\ in braces ${}
2016-06-06 19:19:40 -05:00
Paul Hinze
8e05f061d6
strconv: Fix escaped backslashes \\ in braces ${}
Fixes https://github.com/hashicorp/terraform/issues/6359 and several
related issues by unescaping a double backslash within braces to a
single backslash.

This bumps into the bit of HIL that still hangs out in HCL - for values
that aren't interpolated, like Terraform's variable defaults - users
were unable to get a backslash to show up within `${}`.

That's because `${}` is handled specially to allow for, e.g., double
quotes inside of braces.

Here, we add `\\` as a special cased escape (along with `\"`) so users
can get backslashes in these scenarios by doubling them up.
2016-06-06 19:05:05 -05:00
vishalnayak
b5065874bc Skip a nil item during filtering 2016-05-10 20:33:58 -04:00
Merlin Gaillard
6ffac0df10 ignore fields with "-" tag name when decoding struct 2016-05-05 17:14:34 +02:00
Dan Carley
1793ae0f56 hcl/fmtcmd: Clarify docs for Options.Diff
This description was originally copied straight from gofmt[0]. But as noted
in hashicorp/terraform#6343, the "instead of rewriting" suggests that it
disables the `Write` option, whereas it is possible to enable both.

[0]: https://golang.org/src/cmd/gofmt/gofmt.go#L31
2016-04-28 18:03:01 +01:00
Paul Hinze
9a905a34e6 Merge pull request #115 from hashicorp/phinze/fmtcmd-remove-extra-newline
fmtcmd: Remove extra newline
2016-04-26 17:13:00 -05:00
Paul Hinze
2f980537dd
fmtcmd: Remove extra newline
The fmtcmd tests weren't running before due to the same build tag
problem as #112, so didn't catch the fact that there was an extra
newline being added here, which is now doubled thanks to #112.

Fixing up the build tag reveals failing tests - removing the extra
newline fixes the tests.
2016-04-26 16:06:22 -05:00
James Nugent
27a57f2605 Merge pull request #112 from hashicorp/phinze/print-trailing-newline-at-eof
printer: output EOF newline in formatted hcl
2016-04-13 10:25:42 -07:00
Paul Hinze
2eb00dcf94 printer: output EOF newline in formatted hcl
Noticed that the `hclfmt` tool (which uses hcl/printer) was chomping
the trailing newline from config files.

Here we switch to the more conventional newline-at-EOF output.

In the process of changing this, I realized that:

 * The printer_test.go build tag was wrong, so it wasn't running
 * The format() test helper was not exercising Format

So both of those fixes are included here
2016-04-06 09:09:04 -05:00
James Nugent
2604f3bda7 Merge pull request #91 from hashicorp/f-indented-heredocs
Add support for indented HEREDOC terminators
2016-03-21 14:46:21 +00:00
James Nugent
2584e26c89 Fix tests on Windows line endings 2016-03-21 14:33:19 +00:00
James Nugent
f5480db646 Remove hanging indent on HEREDOCs with <<- prefix
This commit adds support for removing a hanging indent from HEREDOC
token contents if the marker is prefixed with <<-. For example, given
the HCL definition:

my_long_var_name = <<-EOF
                   {
                       "key": "value"
                   }
                   EOF

The value of the HEREDOC will be:

{
    "key": "value"
}

This is useful for use cases where indentation or leading whitespace
is important.

The rule applied is that the prefix on the terminating marker will be
removed from each each line in the HEREDOC, providing all the lines have
that prefix (i.e. every line is at least as indented as the terminating
marker, and using the same mechanism of tabs vs spaces).
2016-03-21 14:12:20 +00:00
James Nugent
3ad5dd62fd Add support for indented HEREDOC terminators
This PR adds support for the style of HEREDOC often used in Ruby which
allows the terminating marker to be indented if the HEREDOC is started
with the sequence "<<-" rather than the usual "<<". This allows users to
express documents with more natural indentation:

resource "template_file" "test" {
    template = <<-HEREDOC
        First Line
        Second Line
    HEREDOC
}

Note that this does not attempt to add any semantics around removing
hanging indent from the actual text of the document, so extra
indentation would still be present. We could make use of the canonical
style for HCL herre to remove the hanging indent in the style of Ruby
which would probably be more predictable for users.
2016-03-21 14:12:20 +00:00
James Nugent
d27ef81edb Merge pull request #106 from hashicorp/windows-ignore-tests
Temporarily ignore printer and fmt tests on Windows
2016-03-21 14:09:04 +00:00
James Nugent
597882917a Temporarily gnore printer and fmt tests on Windows
The red CI build on Windows is making it harder to process actual bugs -
neither printer or fmt are used in any HC projects currently so
ignoring the tests on AppVeyor/Windows seems reasonable for now. At some
point they need fixing to account for line endings.
2016-03-21 13:56:16 +00:00
James Nugent
35d2bfae4f Merge pull request #105 from hashicorp/b-terraform-5470
Return an error if object keys are not strings
2016-03-21 13:53:07 +00:00
James Nugent
d41432d951 Return an error if object keys are not strings
This now gives an error instead of a panic when encountering
configuration such as described in hashicorp/terraform#5740:

```
resource "aws" "web" {
  provider = "aws" {
    region = "us-west-2"
  }
}
```

We now return an error message - "hcl object keys must be a string"
instead of crashing.

Fixes hashicorp/terraform#5740.
2016-03-21 13:32:31 +00:00
Mitchell Hashimoto
32f2911ca2 Merge pull request #104 from hashicorp/b-windows-scanner-tests
Fix scanner tests on Windows
2016-03-20 22:34:57 -05:00
James Nugent
9832b69cfd Fix line endings in hclfmt test 2016-03-21 00:17:10 +00:00
James Nugent
1e8f2d1561 Fix the appveyor build script 2016-03-21 00:09:29 +00:00