fix: prevent escaped non-ASCII paths in git diff output
#29
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.
Summary
This PR ensures that file paths containing non-ASCII characters (e.g., Chinese) are correctly handled when running:
By default, Git escapes non-ASCII characters using octal sequences (e.g.,
\351\203\221) in its output. This can lead to incorrect file path handling in Node.js environments, especially when attempting to read or process such files.Added git config
core.quotepathfalse before invokinggit diff, so Git outputs paths as human-readable UTF-8 strings rather than escaped octal sequences.Example
This issue was encountered in a real-world use case involving the zotero-chinese/styles project, which stores hundreds of CSL-M styles—a variant of the Citation Style Language.
We use
autofix-cito automatically commit preview information for these styles (such asindex.mdandmetadata.json) so that users can easily browse and choose the styles they need. Each style is stored in a directory named after the corresponding journal, which often contains CJK characters.For commit: zotero-chinese/styles.dev@38c7a1d
After the CI ran: https://github.com/zotero-chinese/styles/actions/runs/15507982187
It should have recorded
index.mdandmetadata.jsonas additions. However, due to the presence of Chinese characters in the directory name, Node.js failed to read the files, and the action incorrectly recorded them as deletions in the artifact:Incorrect artifact output (before fix):
{ "version": 1, "changes": { "additions": [], "deletions": [ { "path": "\"src/\\351\\203\\221\\345\\267\\236\\345\\244\\247\\345\\255\\246\\357\\274\\210\\347\\240\\224\\347\\251\\266\\347\\224\\237\\357\\274\\211/index.md\"" }, { "path": "\"src/\\351\\203\\221\\345\\267\\236\\345\\244\\247\\345\\255\\246\\357\\274\\210\\347\\240\\224\\347\\251\\266\\347\\224\\237\\357\\274\\211/metadata.json\"" } ] }, "failFast": true }After fix: https://github.com/zotero-chinese/styles.dev/actions/runs/15516434383