Sorry, something went wrong.
Codecov Report✅ All modified and coverable lines are covered by tests. @@ Coverage Diff @@
## master #1966 +/- ##
=======================================
Coverage 98.23% 98.23%
=======================================
Files 61 61
Lines 2779 2779
=======================================
Hits 2730 2730
Misses 49 49
☔ View full report in Codecov by Sentry. |
Sorry, something went wrong.
|
Updated per @bearomorphism's review: You're right — the original test_init_empty_config_content_uses_allow_unicode was misleading. It pre-seeded the file with an emoji and asserted the emoji survived init_empty_config_content(), but the method only writes {"commitizen": {}} (ASCII-only) in append mode, so allow_unicode=True had no observable effect on the test outcome. Replaced it with a more honest test that uses mocker.spy(yaml, "dump") to assert the keyword argument is passed. This protects against future regressions if anyone ever adds a Unicode default to the dict, without pretending to test behaviour that doesn't currently happen. Both test_set_key_preserves_unicode (which covers the actual #1164 regression) and the new spy-based test pass. |
Sorry, something went wrong.
There was a problem hiding this comment.
This PR fixes YAML config rewrites so non-ASCII characters (e.g., emojis in bump_message) are preserved as literal Unicode instead of being escaped to \Uxxxxxxxx sequences when cz bump updates .cz.yaml/cz.yaml.
Changes:
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| commitizen/config/yaml_config.py | Enables Unicode emission in YAML serialization by adding allow_unicode=True to yaml.dump call sites. |
| tests/test_conf.py | Adds regression + forwarding tests to prevent reintroducing YAML Unicode escaping. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Sorry, something went wrong.
Description
Closes #1164.
Why
PyYAML's yaml.dump defaults to ASCII-only output: any non-ASCII codepoint is escaped using Python's \Uxxxx notation. This means a .cz.yaml containing a literal emoji — for example 🚀 in bump_message — is silently mangled every time cz bump rewrites the config, replacing the readable character with \U0001F680.
Reported by @syepes on commitizen 3.27.0 / Python 3.12 / macOS (#1164), with before-and-after screenshots showing the escape introduced by cz bump --increment PATCH. A triage note from the open-issues audit (2026-05-09) confirmed the bug still reproduces on master (v4.15.1): after cz bump, the bump_message key reads "\U0001F680 chore(release): …" instead of "🚀 chore(release): …".
The root cause is that both yaml.dump call sites in commitizen/config/yaml_config.py — init_empty_config_content (line 33) and set_key (line 66) — omit allow_unicode=True. PyYAML documents that this flag causes non-ASCII codepoints to be written as literal UTF-8 bytes rather than escape sequences; the output remains valid YAML and valid UTF-8.
What changed
How it works
Backward compatibility
Checklist
Was generative AI tooling used to co-author this PR?
Generated-by: Claude following the guidelines
Code Changes
Expected Behavior
Steps to Test This Pull Request
Additional Context
This fix was identified during the open-issues audit tracked in #1964. A triage note (@bearomorphism, 2026-05-09) confirmed the bug reproduces on master (v4.15.1) and pinpointed commitizen/config/yaml_config.py:66 as the root cause, with a symmetric fix needed at line 33 for consistency.
Review note — test update: the initial draft included test_init_empty_config_content_uses_allow_unicode, which pre-seeded a YAML file with 🚀 and asserted the emoji survived init_empty_config_content(). This was misleading: because init_empty_config_content opens in append mode and writes only {"commitizen": {}}, the assertion would pass regardless of whether allow_unicode=True was present. The test has been replaced with a mocker.spy-based assertion that directly verifies the keyword argument is forwarded, without pretending to test behaviour that doesn't currently happen (see PR comment).