hcl icon indicating copy to clipboard operation
hcl copied to clipboard

allow "empty" (0 length or whitespace only) lines in heredoc

Open jhriggs opened this issue 5 years ago • 4 comments

jhriggs avatar Dec 19 '19 15:12 jhriggs

Mostly a duplicate of #259 that I found after I whipped this up. :-/ Looks like that one is waiting on CLA, though.

jhriggs avatar Dec 19 '19 15:12 jhriggs

Hi @jhriggs! Thanks for working on this.

I'm more familiar with the v2 implementation of HCL than the v1 implementation, so I'm not sure I fully understand the implications of this.

From reviewing #258 I think I understand the problem this was intended to solve: I guess the v1 parser expects that any "blank lines" in a flush heredoc should be represented as enough whitespace to "line up" with the other lines, rather than as truly blank lines. Is that right?

Unfortunately fixing this now seems kinda tricky because technically this would be a breaking change. The extra newline on the end is more likely to be problematic in practice, but it's also within the realm of possibility that existing configurations out there are incorrectly using flush heredocs and depending on the result being interpreted as a plain heredoc, in which case this would cause a new result for them.

HCL v2 has already made this breaking change (along with many others); its heredoc syntax is defined in a different way that already accounts for blank lines. HCL v1 is essentially frozen at this point, "bugs and all", because existing systems are depending on its current behavior.

For that reason, I think we won't be able to make a change like this to the v1 line of HCL. While I do agree that the behavior here is unfortunate, HCL v1 is defined entirely by its implementation and so almost any change to it would risk breaking existing usage. :confounded:

apparentlymart avatar Dec 19 '19 18:12 apparentlymart

I get it @apparentlymart. I am not particularly surprised by the response, but I figured it was worth a try! BTW, I didn't add a newline, I don't believe. It was just fixing some tests.

Basically, as it is, this:

  foo = <<-EOF
        bar

        baz
        EOF

currently gives you:

        bar

        baz

instead of the "expected"(?):

bar

baz

jhriggs avatar Dec 19 '19 19:12 jhriggs

CLA assistant check
All committers have signed the CLA.

hashicorp-cla avatar Sep 09 '21 10:09 hashicorp-cla