mikefarah / yq

yq is a portable command-line YAML, JSON, XML, CSV, TOML and properties processor
https://mikefarah.gitbook.io/yq/
MIT License
11.98k stars 589 forks source link

YAML property names get mixed up if one contains asterisk `*` #1323

Open qqilihq opened 2 years ago

qqilihq commented 2 years ago

Describe the bug

YAML property names get replaced if one of them contains an asterisk * when running the “merge YAML” example.

Below, this is the case for image/*. Note that for this bug report, I’m “merging” just a single YAML to illustrate the issue.

Version of yq: 4.27.3 Operating system: mac Installed via: homebrew

Input Yaml data1.yml:

example:
  image/webp:
  image/svg+xml:
  image/jpeg:
  image/png:
  image/*:

Command The command you ran:

yq ea '. as $item ireduce ({}; . * $item )' data1.yml

Actual behavior

example:
  image/*:
  image/*:
  image/*:
  image/*:

Expected behavior

example:
  image/webp:
  image/svg+xml:
  image/jpeg:
  image/png:
  image/*:

Additional context

mikefarah commented 2 years ago

Ah yeah this is a hang-over (and backwards compatibility) for yq 3 - where '*' was used as a wildcard.

Hmm I think the best way to fix this without impacting existing users is to add a new flag that disables that functionality :/

qqilihq commented 2 years ago

Many thanks for the feedback. I worked around this for now by sed'ing the * to a placeholder, then running yq and then replacing it back. This works for now :-)

bitdivine commented 5 months ago

A flag such as --legacy that enables the old behaviour would also work. This way existing users would be impacted, but all they would have to do is to add --legacy to any affected scripts when they update. That way they don't have too much disruption but know that they need to sit down and update their scripts at some time. They will have had due warning that this thing is going to go away. Otherwise new users will have to tangle with old patterns that maybe you don't really want any more.