Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unsetting AllowInvalidUtf8 does nothing #2623

Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
50 changes: 0 additions & 50 deletions src/build/app/settings.rs
Expand Up @@ -80,8 +80,6 @@ impl_settings! { AppSettings, AppFlags,
=> Flags::ARGS_NEGATE_SCS,
AllowExternalSubcommands("allowexternalsubcommands")
=> Flags::ALLOW_UNK_SC,
AllowInvalidUtf8("allowinvalidutf8")
=> Flags::UTF8_NONE,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UTF8_NONE would also need to go

AllowLeadingHyphen("allowleadinghyphen")
=> Flags::LEADING_HYPHEN,
AllowNegativeNumbers("allownegativenumbers")
Expand Down Expand Up @@ -170,50 +168,6 @@ impl_settings! { AppSettings, AppFlags,
/// [`App`]: crate::App
#[derive(Debug, PartialEq, Copy, Clone)]
pub enum AppSettings {
/// Specifies that any invalid UTF-8 code points should *not* be treated as an error.
/// This is the default behavior of `clap`.
///
/// **NOTE:** Using argument values with invalid UTF-8 code points requires using
/// [`ArgMatches::value_of_os`], [`ArgMatches::values_of_os`], [`ArgMatches::value_of_lossy`],
/// or [`ArgMatches::values_of_lossy`] for those particular arguments which may contain invalid
/// UTF-8 values
///
/// **NOTE:** This rule only applies to argument values. Flags, options, and
/// [`subcommands`] themselves only allow valid UTF-8 code points.
///
/// # Platform Specific
///
/// Non Windows systems only
///
/// # Examples
///
#[cfg_attr(not(unix), doc = " ```ignore")]
#[cfg_attr(unix, doc = " ```")]
/// # use clap::{App, AppSettings};
/// use std::ffi::OsString;
/// use std::os::unix::ffi::{OsStrExt,OsStringExt};
///
/// let r = App::new("myprog")
/// //.setting(AppSettings::AllowInvalidUtf8)
/// .arg("<arg> 'some positional arg'")
/// .try_get_matches_from(
/// vec![
/// OsString::from("myprog"),
/// OsString::from_vec(vec![0xe9])]);
///
/// assert!(r.is_ok());
/// let m = r.unwrap();
/// assert_eq!(m.value_of_os("arg").unwrap().as_bytes(), &[0xe9]);
/// ```
///
/// [`ArgMatches::value_of_os`]: crate::ArgMatches::value_of_os()
/// [`ArgMatches::values_of_os`]: crate::ArgMatches::values_of_os()
/// [`ArgMatches::value_of_lossy`]: crate::ArgMatches::value_of_lossy()
/// [`ArgMatches::values_of_lossy`]: crate::ArgMatches::values_of_lossy()
/// [`subcommands`]: crate::App::subcommand()
// TODO: Either this or StrictUtf8
AllowInvalidUtf8,

/// Specifies that leading hyphens are allowed in all argument *values*, such as negative numbers
/// like `-10`. (which would otherwise be parsed as another flag or option)
///
Expand Down Expand Up @@ -1146,10 +1100,6 @@ mod test {
"allowexternalsubcommands".parse::<AppSettings>().unwrap(),
AppSettings::AllowExternalSubcommands
);
assert_eq!(
"allowinvalidutf8".parse::<AppSettings>().unwrap(),
AppSettings::AllowInvalidUtf8
);
assert_eq!(
"allowleadinghyphen".parse::<AppSettings>().unwrap(),
AppSettings::AllowLeadingHyphen
Expand Down
3 changes: 0 additions & 3 deletions tests/app_settings.rs
Expand Up @@ -595,13 +595,10 @@ fn unset_setting() {
#[test]
fn unset_settings() {
let m = App::new("unset_settings");
assert!(&m.is_set(AppSettings::AllowInvalidUtf8));
assert!(&m.is_set(AppSettings::ColorAuto));

let m = m
.unset_global_setting(AppSettings::AllowInvalidUtf8)
.unset_global_setting(AppSettings::ColorAuto);
assert!(!m.is_set(AppSettings::AllowInvalidUtf8), "{:#?}", m);
assert!(!m.is_set(AppSettings::ColorAuto), "{:#?}", m);
}

Expand Down