on master help sign in
Add check for a non-zero value for tab width (#7178)
commit77e9a22aff13a12cb17d67dbd1bc47aa5d5072f4 authorIlya Sovtsov <70143303+bo1led-owl@users.noreply.github.com> dateWed 7 Jun 2023, 12:51 (3 years ago) parent204bac1
1 file changed+16
helix-core/src/syntax.rs+16
helix-core/src/syntax.rs+16
@@ -48,6 +48,21 @@ where
4848 .transpose()
4949}
5050
51+fn deserialize_tab_width<'de, D>(deserializer: D) -> Result<usize, D::Error>
52+where
53+ D: serde::Deserializer<'de>,
54+{
55+ usize::deserialize(deserializer).and_then(|n| {
56+ if n > 0 && n <= 16 {
57+ Ok(n)
58+ } else {
59+ Err(serde::de::Error::custom(
60+ "tab width must be a value from 1 to 16 inclusive",
61+ ))
62+ }
63+ })
64+}
65+
5166pub fn deserialize_auto_pairs<'de, D>(deserializer: D) -> Result<Option<AutoPairs>, D::Error>
5267where
5368 D: serde::Deserializer<'de>,
@@ -424,6 +439,7 @@ pub struct DebuggerQuirks {
424439#[derive(Debug, Serialize, Deserialize)]
425440#[serde(rename_all = "kebab-case")]
426441pub struct IndentationConfiguration {
442+ #[serde(deserialize_with = "deserialize_tab_width")]
427443 pub tab_width: usize,
428444 pub unit: String,
429445}