Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
olets opened this issue Sep 5, 2020 · 0 comments
Labels

Comments

@olets
Copy link

olets commented Sep 5, 2020

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 olets added the bug label Sep 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant