Skip to content

Commit

Permalink
Fix: Don't wrap long strings or drop quotes
Browse files Browse the repository at this point in the history
An issue has presented, where if a string is over 80 characters, it will wrap over to the next line.
This results in sometimes producing invalid variable injections.

Be as true to the source as possible, so keep long lines and quotes
  • Loading branch information
antdking committed May 15, 2020
1 parent fdbfebd commit 1943ee0
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions clean_actions/yaml.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
def _yaml(*, output: io.StringIO = None) -> ruamel.yaml.YAML:
yaml = ruamel.yaml.YAML(output=output)

yaml.preserve_quotes = True
yaml.width = 100000000000

# Strip out aliases + anchors when dumping
yaml.constructor.flatten_mapping = _flatten_mapping(yaml.constructor)
yaml.representer.ignore_aliases = lambda x: True
Expand Down
20 changes: 20 additions & 0 deletions tests/cases/preserve-quotes.case.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
it: Preserves double quotes on a string
given: |
foo: "bar"
expect: |
foo: "bar"
---
it: Preserves single quotes on a string
given: |
foo: 'bar'
expect: |
foo: 'bar'
---
it: Preserves no quotes on a string
given: |
foo: bar
expect: |
foo: bar
6 changes: 6 additions & 0 deletions tests/cases/preserves-long-strings.case.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
it: Does not wrap long strings
given: |
foo: This is a really really really really really really long string that we don't want to wrap
expect: |
foo: This is a really really really really really really long string that we don't want to wrap

0 comments on commit 1943ee0

Please sign in to comment.