This is an archive of the discontinued Mercurial Phabricator instance.

rust-utils: add normalize_case util to mirror Python one
ClosedPublic

Authored by Alphare on Aug 22 2019, 8:54 AM.

Details

Summary

While we still don't handle filenames properly cross-platform, this at least
sticks closer to the Python behavior.

Diff Detail

Repository
rHG Mercurial
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.

Event Timeline

Alphare created this revision.Aug 22 2019, 8:54 AM
kevincox accepted this revision.Aug 28 2019, 5:21 AM
This revision was not accepted when it landed; it landed in state Needs Review.
This revision was automatically updated to reflect the committed changes.
yuja added a subscriber: yuja.Aug 31 2019, 11:02 PM

+/ TODO improve handling of utf8 file names. Our overall strategy for
+
/ filenames has to be revisited anyway, since Windows is UTF-16.
+pub fn normalize_case(bytes: &[u8]) -> Vec<u8> {
+ #[cfg(windows)] // NTFS compares via upper()
+ return bytes.to_ascii_uppercase();
+ #[cfg(unix)]
+ bytes.to_ascii_lowercase()
+}

HFS+ has more complex rules, and some were the source of security issue.