Line wrapping exceeds requested width with for quoted and folded strings
ruamel.yaml is a YAML 1.2 parser/emitter for Python
Brought to you by:
anthon
Line wrapping works correctly for unquoted strings but doesn't for quoted and folded ones. This causes issues with formatters/linters which are based on ruamel.yaml (e.g. ansible-lint --fix).
# Unquoted: OK (max: 80)
echo "key: $(seq -s " " 1 150)" | uv run python3 -c "import sys; from ruamel.yaml import YAML; yaml = YAML(); yaml.preserve_quotes = True; yaml.dump(yaml.load(sys.stdin), sys.stdout)" | wc -L
# OUTPUT: 80
# Quoted: Wrong (max: 83)
echo "key: \"$(seq -s " " 1 150)\"" | uv run python3 -c "import sys; from ruamel.yaml import YAML; yaml = YAML(); yaml.preserve_quotes = True; yaml.dump(yaml.load(sys.stdin), sys.stdout)" | wc -L
# OUTPUT: 83
# Folded: Wrong (max: 82)
echo -e "key: >\n $(seq -s " " 1 150)" | uv run python3 -c "import sys; from ruamel.yaml import YAML; yaml = YAML(); yaml.preserve_quotes = True; yaml.dump(yaml.load(sys.stdin), sys.stdout)" | wc -L
# OUTPUT: 82