From 6df5fa84408447d59136de5cd405a57e06ef1491 Mon Sep 17 00:00:00 2001 From: Phil Gebhardt Date: Thu, 21 Nov 2019 15:20:26 -0800 Subject: [PATCH] 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)