From 52bcecfd4a2f122f445babf470fc10d6878f525e Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Mon, 3 Aug 2020 22:53:06 +0300 Subject: [PATCH] conf.rs: reject unknown configuration options Closes #11 --- config_macros.rs | 1 + src/conf.rs | 3 +++ src/conf/composing.rs | 1 + src/conf/listing.rs | 1 + src/conf/notifications.rs | 1 + src/conf/overrides.rs | 7 +++++++ src/conf/pager.rs | 1 + src/conf/pgp.rs | 1 + src/conf/shortcuts.rs | 1 + src/conf/tags.rs | 1 + src/conf/terminal.rs | 2 +- src/conf/themes.rs | 3 +++ 12 files changed, 22 insertions(+), 1 deletion(-) diff --git a/config_macros.rs b/config_macros.rs index 64733108..ae12b718 100644 --- a/config_macros.rs +++ b/config_macros.rs @@ -134,6 +134,7 @@ use super::*; let literal_struct = quote! { #[derive(Debug, Serialize, Deserialize, Clone)] + #[serde(deny_unknown_fields)] pub struct #override_ident { #(#field_tokentrees),* } diff --git a/src/conf.rs b/src/conf.rs index 237d14a2..0dc11f62 100644 --- a/src/conf.rs +++ b/src/conf.rs @@ -108,6 +108,7 @@ macro_rules! mailbox_settings { } #[derive(Default, Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct MailUIConf { #[serde(default)] pub pager: PagerSettingsOverride, @@ -191,6 +192,7 @@ impl FileAccount { } #[derive(Debug, Clone, Default, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct FileSettings { pub accounts: HashMap, #[serde(default)] @@ -821,6 +823,7 @@ mod pp { } #[derive(Debug, Clone, Default, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct LogSettings { #[serde(default)] log_file: Option, diff --git a/src/conf/composing.rs b/src/conf/composing.rs index 0d7e2576..ea1f5728 100644 --- a/src/conf/composing.rs +++ b/src/conf/composing.rs @@ -25,6 +25,7 @@ use std::collections::HashMap; /// Settings for writing and sending new e-mail #[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(deny_unknown_fields)] pub struct ComposingSettings { /// A command to pipe new emails to /// Required diff --git a/src/conf/listing.rs b/src/conf/listing.rs index 2904e5c7..ea86f595 100644 --- a/src/conf/listing.rs +++ b/src/conf/listing.rs @@ -25,6 +25,7 @@ use melib::{MeliError, Result}; /// Settings for mail listings #[derive(Debug, Deserialize, Clone, Serialize)] +#[serde(deny_unknown_fields)] pub struct ListingSettings { /// Number of context lines when going to next page. /// Default: 0 diff --git a/src/conf/notifications.rs b/src/conf/notifications.rs index f600440f..808634b2 100644 --- a/src/conf/notifications.rs +++ b/src/conf/notifications.rs @@ -23,6 +23,7 @@ use super::default_vals::{internal_value_false, none}; /// Settings for the notifications function. #[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(deny_unknown_fields)] pub struct NotificationsSettings { /// A command to pipe notifications through /// Default: None diff --git a/src/conf/overrides.rs b/src/conf/overrides.rs index 1d5672e9..a3aa588a 100644 --- a/src/conf/overrides.rs +++ b/src/conf/overrides.rs @@ -23,6 +23,7 @@ use super::*; #[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(deny_unknown_fields)] pub struct PagerSettingsOverride { #[doc = " Number of context lines when going to next page."] #[doc = " Default: 0"] @@ -94,6 +95,7 @@ impl Default for PagerSettingsOverride { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(deny_unknown_fields)] pub struct ListingSettingsOverride { #[doc = " Number of context lines when going to next page."] #[doc = " Default: 0"] @@ -131,6 +133,7 @@ impl Default for ListingSettingsOverride { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(deny_unknown_fields)] pub struct NotificationsSettingsOverride { #[doc = " A command to pipe notifications through"] #[doc = " Default: None"] @@ -161,6 +164,7 @@ impl Default for NotificationsSettingsOverride { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(deny_unknown_fields)] pub struct ShortcutsOverride { #[serde(default)] pub general: Option, @@ -199,6 +203,7 @@ impl Default for ShortcutsOverride { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(deny_unknown_fields)] pub struct ComposingSettingsOverride { #[doc = " A command to pipe new emails to"] #[doc = " Required"] @@ -235,6 +240,7 @@ impl Default for ComposingSettingsOverride { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(deny_unknown_fields)] pub struct TagsSettingsOverride { #[serde(deserialize_with = "tag_color_de")] #[serde(default)] @@ -253,6 +259,7 @@ impl Default for TagsSettingsOverride { } #[derive(Debug, Serialize, Deserialize, Clone)] +#[serde(deny_unknown_fields)] pub struct PGPSettingsOverride { #[doc = " auto verify signed e-mail according to RFC3156"] #[serde(alias = "auto-verify-signatures")] diff --git a/src/conf/pager.rs b/src/conf/pager.rs index 226bc317..99754037 100644 --- a/src/conf/pager.rs +++ b/src/conf/pager.rs @@ -28,6 +28,7 @@ use melib::{MeliError, Result, ToggleFlag}; /// Settings for the pager function. #[derive(Debug, Deserialize, Clone, Serialize)] +#[serde(deny_unknown_fields)] pub struct PagerSettings { /// Number of context lines when going to next page. /// Default: 0 diff --git a/src/conf/pgp.rs b/src/conf/pgp.rs index 3d0fd429..310d8504 100644 --- a/src/conf/pgp.rs +++ b/src/conf/pgp.rs @@ -23,6 +23,7 @@ use super::default_vals::*; /// Settings for digital signing and encryption #[derive(Debug, Deserialize, Clone, Serialize)] +#[serde(deny_unknown_fields)] pub struct PGPSettings { /// auto verify signed e-mail according to RFC3156 #[serde(default = "true_val", alias = "auto-verify-signatures")] diff --git a/src/conf/shortcuts.rs b/src/conf/shortcuts.rs index 04acbd72..21b222e7 100644 --- a/src/conf/shortcuts.rs +++ b/src/conf/shortcuts.rs @@ -35,6 +35,7 @@ macro_rules! shortcut { } #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct Shortcuts { #[serde(default)] pub general: GeneralShortcuts, diff --git a/src/conf/tags.rs b/src/conf/tags.rs index cee7a55f..42f94be0 100644 --- a/src/conf/tags.rs +++ b/src/conf/tags.rs @@ -29,6 +29,7 @@ use std::collections::{hash_map::DefaultHasher, HashMap, HashSet}; use std::hash::Hasher; #[derive(Debug, Deserialize, Clone, Serialize)] +#[serde(deny_unknown_fields)] pub struct TagsSettings { #[serde(default, deserialize_with = "tag_color_de")] pub colors: HashMap, diff --git a/src/conf/terminal.rs b/src/conf/terminal.rs index df3a4f83..f872e105 100644 --- a/src/conf/terminal.rs +++ b/src/conf/terminal.rs @@ -28,7 +28,7 @@ use melib::{MeliError, Result, ToggleFlag}; /// Settings for terminal display #[derive(Debug, Deserialize, Clone, Serialize)] -#[serde(default)] +#[serde(default, deny_unknown_fields)] pub struct TerminalSettings { /// light, dark pub theme: String, diff --git a/src/conf/themes.rs b/src/conf/themes.rs index cc0ff8f7..a00d878b 100644 --- a/src/conf/themes.rs +++ b/src/conf/themes.rs @@ -306,6 +306,7 @@ const DEFAULT_KEYS: &[&str] = &[ /// `ThemeAttributeInner` but with the links resolved. #[derive(Debug, PartialEq, Eq, Clone, Default, Copy, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct ThemeAttribute { pub fg: Color, pub bg: Color, @@ -314,6 +315,7 @@ pub struct ThemeAttribute { /// Holds {fore,back}ground color and terminal attribute values. #[derive(Debug, Clone, Serialize, Deserialize)] +#[serde(deny_unknown_fields)] pub struct ThemeAttributeInner { #[serde(default)] fg: ThemeValue, @@ -799,6 +801,7 @@ impl<'de> Deserialize<'de> for Themes { rest: ThemeAttributeInnerOptions, } #[derive(Deserialize, Default)] + #[serde(deny_unknown_fields)] struct ThemeAttributeInnerOptions { #[serde(default)] fg: Option>,