This is an archive of the discontinued Mercurial Phabricator instance.

pycompat: implement a shlexquote that properly handles bytes
AbandonedPublic

Authored by indygreg on Oct 8 2019, 12:42 AM.

Details

Reviewers
None
Group Reviewers
hg-reviewers
Summary

2cc453284d5 introduced this function call to for mail.py. This broke Python
3 because shlex.quote() expects str, not bytes. In order to unbust it,
we need to normalize bytes to str then go back to bytes to appease the
caller.

This is a bit ugly. But I don't see any other obvious solution.

Diff Detail

Repository
rHG Mercurial
Lint
Lint Skipped
Unit
Unit Tests Skipped

Event Timeline

indygreg created this revision.Oct 8 2019, 12:42 AM
marmoute added inline comments.
mercurial/pycompat.py
343

It might be a silly questions, but why are we going through latin-1 instead of utf-8 or any other crazy encoding ?

indygreg added inline comments.Oct 8 2019, 11:05 AM
mercurial/pycompat.py
343

Because the underlying string is likely raw bytes and latin-1 will preserve those code points. i.e. we don't care what the encoding is: just that we can pass str to shlex.quote.

indygreg abandoned this revision.Oct 9 2019, 11:15 PM

Yuya's patch fixed the test failure and is a better solution.