From 4b0048666aaa5efd6d12841fa8feb6c2cf1905af Mon Sep 17 00:00:00 2001 From: Ed Page Date: Thu, 4 Nov 2021 12:23:02 -0500 Subject: [PATCH] fix: Allow unicode aware case insensitivity In #2985, I noticed #2834 was incomplete, there were case-insensitive comparisons we were doing without being unicode aware (when compile options are set). The downside is that each comparison will require a UTF-8 validation. These seem to be in more of corners of the API, rather than in common calls in common usages, so hopefully that isn't too much of a problem. --- src/parse/matches/matched_arg.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/parse/matches/matched_arg.rs b/src/parse/matches/matched_arg.rs index 361d430a..92fb1c02 100644 --- a/src/parse/matches/matched_arg.rs +++ b/src/parse/matches/matched_arg.rs @@ -5,6 +5,7 @@ use std::{ slice::Iter, }; +use crate::util::eq_ignore_case; use crate::INTERNAL_ERROR_MSG; // TODO: Maybe make this public? @@ -127,7 +128,8 @@ impl MatchedArg { pub(crate) fn contains_val(&self, val: &str) -> bool { self.vals_flatten().any(|v| { if self.case_insensitive { - v.eq_ignore_ascii_case(val) + // If `v` isn't utf8, it can't match `val`, so `OsStr::to_str` should be fine + v.to_str().map_or(false, |v| eq_ignore_case(v, val)) } else { OsString::as_os_str(v) == OsStr::new(val) }