Skip to content

deny_unknown_fields in the configuration file #2572

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ fn is_legacy_format(table: &Value) -> bool {
/// Configuration options which are specific to the book and required for
/// loading it from disk.
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
#[serde(default, rename_all = "kebab-case")]
#[serde(default, rename_all = "kebab-case", deny_unknown_fields)]
pub struct BookConfig {
/// The book's title.
pub title: Option<String>,
Expand Down Expand Up @@ -894,6 +894,17 @@ mod tests {
assert_eq!(got.html_config().unwrap(), html_should_be);
}

#[test]
#[should_panic(expected = "Invalid configuration file")]
fn fail_on_invalid_config_field() {
let src = r#"
[book]
password = "Secret"
"#;

Config::from_str(src).unwrap();
}

#[test]
fn disable_runnable() {
let src = r#"
Expand Down