mrbaseman / parse_yaml

a simple yaml parser implemented in bash
GNU General Public License v3.0
165 stars 37 forks source link

wrong results if variables are set #19

Closed benwalch closed 1 year ago

benwalch commented 1 year ago

parse_yaml produces wrong results if a variable i is set to a value in current bash session.

Reproduce:

  1. set value to variable i: $ i="ZZZ test string ZZZ"
  2. echo $(parse_yaml path/to/valid/yaml.yaml)

The output contains strings with of the initial contents of the variable $i of the current bash session.

An approach for solving this issue could be inside the parse_yaml function to back up the current value of $i in a temporary variable, clear the $i variable, run the function, and then write back the backup to the variable. Or, just don't care about the contents of $i (since its use case is 99% a temporary loop variable) and clear it at the beginning of the function.

mrbaseman commented 1 year ago

good catch! I think we have been messing with the temporary variables anyway, so I think it didn't hurt so far - just until you have spotted that the result is not the expected one in this particular case. I'd go with the proposed fix. Thanks for this contribution.