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

yamlfix squashes spaces in block strings #231

Open
wrouesnel opened this issue Apr 5, 2023 · 2 comments · May be fixed by #232
Open

yamlfix squashes spaces in block strings #231

wrouesnel opened this issue Apr 5, 2023 · 2 comments · May be fixed by #232
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@wrouesnel
Copy link

Description

When files contain block strings, yamlfix will squash white space and change the string.

Current behavior

Given the file:

# original.yml
---
key: |
  # This is a value #
  #      X          #

yamlfix original.yml results in:

---
key: |-
  # This is a value  #
  #      X  #

Desired behavior

Strings in block quotes should remain semantically equivalent, or ideally not be modified at all. As it is, white space is removed.

Environment

------------------------------------------------------------------
     yamlfix: 1.9.0
     Python: 3.10.6
     Platform: Linux-5.15.0-27-generic-x86_64-with-glibc2.35
------------------------------------------------------------------
@wrouesnel wrouesnel added the bug Something isn't working label Apr 5, 2023
@lyz-code
Copy link
Owner

lyz-code commented Apr 5, 2023

Hi @wrouesnel thank you for taking the time to open an issue. I can reproduce the issue and agree that it should be fixed. I can't guarantee that it will be fixed soon though :( so if you can, please make a PR :)

@lyz-code lyz-code added the help wanted Extra attention is needed label Apr 5, 2023
wrouesnel added a commit to wrouesnel/yamlfix that referenced this issue Apr 6, 2023
The regex based parsing for fixing comments was breaking block scalars.
By using the ruyaml round trip handler, instead the comment formatting
now can correctly identify block-scalars and avoid mangling them.
wrouesnel added a commit to wrouesnel/yamlfix that referenced this issue Apr 6, 2023
The regex based parsing for fixing comments was breaking block scalars.
By using the ruyaml round trip handler, instead the comment formatting
now can correctly identify block-scalars and avoid mangling them.
@wrouesnel wrouesnel linked a pull request Apr 6, 2023 that will close this issue
2 tasks
@wrouesnel
Copy link
Author

PR opened. The issue was ultimately that regex, line-based parsing incorrectly identified # containing blocks as ending with comments, hence why the issue showed up the way it did.

I've implemented a solution based on running the file into the round-trip parser and modifying comment objects directly, which ensures only comments are ever altered.

wrouesnel added a commit to wrouesnel/yamlfix that referenced this issue Apr 6, 2023
The regex based parsing for fixing comments was breaking block scalars.
By using the ruyaml round trip handler, instead the comment formatting
now can correctly identify block-scalars and avoid mangling them.
wrouesnel added a commit to wrouesnel/yamlfix that referenced this issue Jun 22, 2023
The regex based parsing for fixing comments was breaking block scalars.
By using the ruyaml round trip handler, instead the comment formatting
now can correctly identify block-scalars and avoid mangling them.
wrouesnel added a commit to wrouesnel/yamlfix that referenced this issue Jun 22, 2023
The regex based parsing for fixing comments was breaking block scalars.
By using the ruyaml round trip handler, instead the comment formatting
now can correctly identify block-scalars and avoid mangling them.
wrouesnel added a commit to wrouesnel/yamlfix that referenced this issue Sep 28, 2023
The regex based parsing for fixing comments was breaking block scalars.
By using the ruyaml round trip handler, instead the comment formatting
now can correctly identify block-scalars and avoid mangling them.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants