kislyuk / yq

Command-line YAML, XML, TOML processor - jq wrapper for YAML/XML/TOML documents
https://kislyuk.github.io/yq/
Apache License 2.0
2.57k stars 82 forks source link

Issues parsing file with curly braces {{ }} #115

Closed Lirt closed 3 years ago

Lirt commented 3 years ago

Hello,

I'm trying to parse yaml file with double curly brace pair ({{ }}). If the file contains a curly brace pair used for example in helm or Go templating, it fails with error yq: Error running jq: TypeError: unhashable type: 'collections.OrderedDict'.

Here is example file you can try it on.

---
kind: test
metadata:
  name: test
spec:
  version: {{ .testVersion }}

yq version is 2.12.0.

Lirt commented 3 years ago

It parses well when double curly braces are inside of string, so for example quoted like "{{ .testVersion }}", but also in case of yaml multi-line strings.

Which means this works for example.

---
kind: test
metadata:
  name: test
spec:
  version: |
    {{ .testVersion }}
kislyuk commented 3 years ago

Hi, the unquoted inline scalar with inline double curly braces that you have in your example is not valid YAML, as far as I can tell. Different parsers produce different errors when trying to parse this, and yq could definitely do a better job of informing you that it's invalid, but you guessed correctly that the scalar needs to be quoted. Basically, unquoted { indicates the start of a flow mapping, and this scalar is not a valid flow mapping (and if interpreted as a mapping, wouldn't do what you intended anyway).

Lirt commented 3 years ago

Thank you, it makes sense.

Maybe it will help somebody to track the error message in the future.