From a5b097bce5c8425cb7a423aae7ba0225fd5da7fe Mon Sep 17 00:00:00 2001 From: fef Date: Tue, 20 Dec 2022 14:09:19 +0100 Subject: [PATCH] implement validate for bearcaps --- src/util/bear.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/util/bear.rs b/src/util/bear.rs index 5383d84..c524520 100644 --- a/src/util/bear.rs +++ b/src/util/bear.rs @@ -4,6 +4,7 @@ use std::iter::Peekable; use std::str::Chars; use crate::core::*; +use crate::util::validate::{ResultBuilder, Validate}; const MAX_PARAM_LEN: usize = 16384; @@ -133,6 +134,14 @@ impl<'de> de::Visitor<'de> for BearcapVisitor { } } +impl Validate for Bearcap { + fn validate(&self, builder: ResultBuilder) -> ResultBuilder { + builder.field(&self.url, "url", |f| { + f.check("URL must start with https://", |v| v.starts_with("https://")) + }) + } +} + #[cfg(test)] mod tests { use crate::util::bear::Bearcap;