hashicorp / hashicorp/hcl

HCL printer produces invalid HCL

Open
#233 1 comment 4 reactions 0 assignees View on GitHub
v1
Dominant language
Go
Stars
5.8k
Forks
657
Avg merge
20h 36m
Merged PRs (30d)
6

Description

### Steps to reproduce
When parsing JSON with `github.com/hashicorp/hcl/json/parser` and printing HCL with `github.com/hashicorp/hcl/hcl/printer`, quotes in function args are broken.

ex:
```json
{
"locals": {
"path": "/dev/null",
"file": "${file(\"${local.path}\")}"
}
}
```
Printing this with something like :
```go
ast, err := jsonParser.Parse([]byte(input))
if err != nil {
return "", fmt.Errorf("unable to parse JSON: %s", err)
}

var buff []byte
buffer := bytes.NewBuffer(buff)

err = printer.Fprint(buffer, ast)
if err != nil {
return "", fmt.Errorf("unable to print HCL: %s", err)
}
```
produces:
```hcl
"locals" = {
"path" = "/dev/null"

"file" = "${file(\"${local.path}\")}"
}
```
and it's not valid HCL

### Expected behavior
Parsing from JSON and printing HCL should produce valid HCL

### Actual behavior
HCL printer produces broken HCL

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.