yq icon indicating copy to clipboard operation
yq copied to clipboard

Extra newline possible when appending to an array ending in commented out entry

Open olets opened this issue 4 years ago • 0 comments

Describe the bug

When appending to array an extra newline is appended before the new element if the last element in the array is commented out at the indentation level where the - would be.

This does no harm, reporting in case it reflects a parsing bug that is problematic in some other scenario.

version of yq: 3.3.2 (installed w/ Homebrew) operating system: macOS 10.15.6

Input Yaml Concise yaml document(s) (as simple as possible to show the bug)

data.yml:

b:
  c: 2
  d:
    - new thing
    # - foo thing

Command The command you ran:

yq w data.yaml "b.d[+]" "bar thing"

Actual behavior

b:
  c: 2
  d:
    - new thing
    # - foo thing

    - bar thing

Expected behavior

b:
  c: 2
  d:
    - new thing
    # - foo thing
    - bar thing

or

b:
  c: 2
  d:
    - new thing
    - bar thing
    # - foo thing

Additional context

Compare to when the # is in a different position. In all cases the command is the same

b:
  c: 2
  d:
    - new thing
#    - foo thing
% yq w git-replay.yaml "b.d[+]" "bar thing"
b:
  c: 2
  d:
    - new thing
    - bar thing
#    - foo thing

and

b:
  c: 2
  d:
    - new thing
 #   - foo thing
b:
  c: 2
  d:
    - new thing
    - bar thing
#   - foo thing

and

b:
  c: 2
  d:
    - new thing
  #  - foo thing
% yq w git-replay.yaml "b.d[+]" "bar thing"
b:
  c: 2
  d:
    - new thing
    - bar thing
  #  - foo thing

olets avatar Sep 05 '20 18:09 olets