Add config-parsing-time check for argument count range

This commit is contained in:
Edward Shen 2020-09-27 21:48:17 -04:00
parent 46261bdfa0
commit 83a2ba0f8a
Signed by: edward
GPG key ID: 19182661E818369F

View file

@ -2,7 +2,7 @@ use crate::BunBunError;
use dirs::{config_dir, home_dir};
use log::{debug, info, trace};
use serde::{
de::{self, Deserializer, MapAccess, Visitor},
de::{self, Deserializer, MapAccess, Unexpected, Visitor},
Deserialize, Serialize,
};
use std::collections::HashMap;
@ -138,6 +138,20 @@ impl<'de> Deserialize<'de> for Route {
}
}
if let (Some(min_args), Some(max_args)) = (min_args, max_args) {
if min_args > max_args {
{
return Err(de::Error::invalid_value(
Unexpected::Other(&format!(
"argument count range {} to {}",
min_args, max_args
)),
&"a valid argument count range",
));
}
}
}
let path = path.ok_or_else(|| de::Error::missing_field("path"))?;
Ok(Route {
route_type: get_route_type(&path),