From 77e9a22aff13a12cb17d67dbd1bc47aa5d5072f4 Mon Sep 17 00:00:00 2001 From: Ilya Sovtsov Date: Wed, 7 Jun 2023 12:51:29 +0400 Subject: Add check for a non-zero value for tab width (#7178) --- helix-core/src/syntax.rs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'helix-core') diff --git a/helix-core/src/syntax.rs b/helix-core/src/syntax.rs index c2dd3310..2a5bb974 100644 --- a/helix-core/src/syntax.rs +++ b/helix-core/src/syntax.rs @@ -48,6 +48,21 @@ where .transpose() } +fn deserialize_tab_width<'de, D>(deserializer: D) -> Result +where + D: serde::Deserializer<'de>, +{ + usize::deserialize(deserializer).and_then(|n| { + if n > 0 && n <= 16 { + Ok(n) + } else { + Err(serde::de::Error::custom( + "tab width must be a value from 1 to 16 inclusive", + )) + } + }) +} + pub fn deserialize_auto_pairs<'de, D>(deserializer: D) -> Result, D::Error> where D: serde::Deserializer<'de>, @@ -424,6 +439,7 @@ pub struct DebuggerQuirks { #[derive(Debug, Serialize, Deserialize)] #[serde(rename_all = "kebab-case")] pub struct IndentationConfiguration { + #[serde(deserialize_with = "deserialize_tab_width")] pub tab_width: usize, pub unit: String, } -- cgit v1.2.3-70-g09d2