Skip to content

Commit

Permalink
add no-strict feature to ignore InvalidDirectives
Browse files Browse the repository at this point in the history
Fix for hickory-dns#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.
  • Loading branch information
philgebhardt committed Nov 21, 2019
1 parent f6be686 commit 6df5fa8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ hostname = { version = "0.1.5", optional = true }

[features]
system = ["hostname"]
no-strict = []

[lib]
name = "resolv_conf"
Expand Down
6 changes: 6 additions & 0 deletions src/grammar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -222,7 +223,12 @@ pub(crate) fn parse(bytes: &[u8]) -> Result<Config, ParseError> {
}
}
}
#[cfg(not(feature="no-strict"))]
_ => return Err(InvalidDirective(lineno)),

#[cfg(feature="no-strict")]
_ => /* ignore invalid directives when no-strict */ (),

}
}
Ok(cfg)
Expand Down

0 comments on commit 6df5fa8

Please sign in to comment.