From a6d0b05fba88dcd05366eb9b9733370c2eefd104 Mon Sep 17 00:00:00 2001 From: Lucas Nogueira Date: Thu, 14 Sep 2023 08:36:50 -0300 Subject: [PATCH] validate config --- plugins/deep-link/src/config.rs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/plugins/deep-link/src/config.rs b/plugins/deep-link/src/config.rs index ca437a5e6..80f0a4c08 100644 --- a/plugins/deep-link/src/config.rs +++ b/plugins/deep-link/src/config.rs @@ -6,15 +6,30 @@ #![allow(dead_code)] -use serde::Deserialize; +use serde::{Deserialize, Deserializer}; #[derive(Deserialize)] pub struct AssociatedDomain { + #[serde(deserialize_with = "deserialize_associated_host")] pub host: String, #[serde(default, alias = "path-prefix", rename = "pathPrefix")] pub path_prefix: Vec, } +fn deserialize_associated_host<'de, D>(deserializer: D) -> Result +where + D: Deserializer<'de>, +{ + let host = String::deserialize(deserializer)?; + if let Some((scheme, _host)) = host.split_once("://") { + Err(serde::de::Error::custom(format!( + "host `{host}` cannot start with a scheme, please remove the `{scheme}://` prefix" + ))) + } else { + Ok(host) + } +} + #[derive(Deserialize)] pub struct Config { pub domains: Vec,