Repository navigation
fix: keep non-ASCII characters when writing JSON files - #2140
Open
vinilpolepalli wants to merge 1 commit into
Open
vinilpolepalli wants to merge 1 commit into
vinilpolepalli wants to merge 1 commit into
Conversation
`cz bump` rewrites `.cz.json`, `package.json`, `package-lock.json`, `npm-shrinkwrap.json` and `composer.json` with `json.dumps`, which escapes every non-ASCII character by default. A bump message with an emoji or an author name with an accent became `🚀` or `José` in the file. Pass `ensure_ascii=False`, as `npm` and `composer` themselves do. Assisted By: AI Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2140 +/- ##
=======================================
Coverage 98.29% 98.29%
=======================================
Files 61 61
Lines 2874 2874
=======================================
Hits 2825 2825
Misses 49 49 ☔ View full report in Codecov by Harness. |
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
cz bumprewrites.cz.json,package.json,package-lock.json,npm-shrinkwrap.jsonandcomposer.jsonwithjson.dump/json.dumps. The defaultensure_ascii=Trueescapes every non-ASCII character in the file, so after a bump an emoji inbump_messagebecomes🚀and an author name likeJosébecomesJosé.This passes
ensure_ascii=FalseinJsonConfig.set_key,JsonProvider.set_version(composer) andNpmProvider.set_version. npm and composer also write these files without escaping.It is the JSON version of #1164, which reports the same problem for
.cz.yaml(#1966 fixes the YAML side).Checklist
Was generative AI tooling used to co-author this PR?
Generated-by: Claude Code following the guidelines
Assisted By: AI
Code Changes
uv run poe alllocally to ensure this change passes linter check and tests (ran format, ruff, mypy and the test suite separately; only the GPG-signing tests fail locally becausegpgis not installed, same as on master)Expected Behavior
cz bumpchanges only the version in JSON files. Other values keep their characters as they are.Steps to Test This Pull Request
.cz.json:{ "commitizen": { "name": "cz_conventional_commits", "version": "1.0.0", "bump_message": "🚀 bump: $current_version → $new_version" } }feat: aand runcz bump --yes..cz.jsoncontains"🚀 bump: $current_version → $new_version". With it, the message is unchanged and onlyversionis1.1.0.The same check with
version_provider = "npm"and apackage.jsonwith"author": "José Müller", orversion_provider = "composer"with a Cyrillic description, gaveJosé Müller/Тестbefore and the original text after.Tests:
test_json_provider_handles_various_unicode_charactersnow also callsset_versionand checks the file,test_npm_provider_respects_configured_encoding_for_all_fileschecks that the latin-1 name is kept, andTestJsonConfig::test_set_key_keeps_non_ascii_charactersis new. They fail without the fix and pass with it.Additional Context
Related: #1164 and #1966 (same issue for YAML config).
🤖 Generated with Claude Code