From 6df5fa84408447d59136de5cd405a57e06ef1491 Mon Sep 17 00:00:00 2001 From: Phil Gebhardt Date: Thu, 21 Nov 2019 15:20:26 -0800 Subject: [PATCH 1/2] add no-strict feature to ignore InvalidDirectives Fix for #17 It's sometimes desireable to ignore invalid directives so that the supplied configuration can still be used. This change adds a feature flag `no-strict` that when enabled, does not return an `Err(InvalidDirective(_))` when a directive isn't valid. Instead, it skips over it, allowing the configuration to be used. --- Cargo.toml | 1 + src/grammar.rs | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index d191d86..f3ede5d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -18,6 +18,7 @@ hostname = { version = "0.1.5", optional = true } [features] system = ["hostname"] +no-strict = [] [lib] name = "resolv_conf" diff --git a/src/grammar.rs b/src/grammar.rs index 2ce9a04..5f0367b 100644 --- a/src/grammar.rs +++ b/src/grammar.rs @@ -29,6 +29,7 @@ quick_error!{ display("option at line {} is not recognized", line) } /// Error returned when a invalid directive is found. + #[cfg(not(feature="no-strict"))] InvalidDirective(line: usize) { display("directive at line {} is not recognized", line) } @@ -222,7 +223,12 @@ pub(crate) fn parse(bytes: &[u8]) -> Result { } } } + #[cfg(not(feature="no-strict"))] _ => return Err(InvalidDirective(lineno)), + + #[cfg(feature="no-strict")] + _ => /* ignore invalid directives when no-strict */ (), + } } Ok(cfg) From a9c79fff14f93c9b1325a1f4f9c762a9bafb0d86 Mon Sep 17 00:00:00 2001 From: brian-cook Date: Thu, 9 Sep 2021 12:03:49 -0500 Subject: [PATCH 2/2] rustc 1.55 emitted a warning that patches and features are mutually exclusive. Inverting the the [no-]strict feature means that strict is the option and we no longer need to include a feature when building agent. --- Cargo.toml | 2 +- src/grammar.rs | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 4191738..4436038 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,7 +19,7 @@ hostname = { version = "^0.3", optional = true } [features] system = ["hostname"] -no-strict = [] +strict = [] [lib] name = "resolv_conf" diff --git a/src/grammar.rs b/src/grammar.rs index 96c30cf..5a1660a 100644 --- a/src/grammar.rs +++ b/src/grammar.rs @@ -29,7 +29,7 @@ quick_error!{ display("option at line {} is not recognized", line) } /// Error returned when a invalid directive is found. - #[cfg(not(feature="no-strict"))] + #[cfg(feature="strict")] InvalidDirective(line: usize) { display("directive at line {} is not recognized", line) } @@ -225,10 +225,10 @@ pub(crate) fn parse(bytes: &[u8]) -> Result { } } } - #[cfg(not(feature="no-strict"))] + #[cfg(feature="strict")] _ => return Err(InvalidDirective(lineno)), - #[cfg(feature="no-strict")] + #[cfg(not(feature="strict"))] _ => /* ignore invalid directives when no-strict */ (), }