mirror of https://github.com/fafhrd91/actix-web
test more cases of path validation
This commit is contained in:
parent
a1a9db15ac
commit
329148465d
|
@ -967,7 +967,7 @@ impl ResourceDef {
|
|||
_ => false,
|
||||
})
|
||||
.unwrap_or_else(|| {
|
||||
panic!(r#"path "{}" contains malformed dynamic segment"#, pattern)
|
||||
panic!(r#"pattern "{}" contains malformed dynamic segment"#, pattern)
|
||||
});
|
||||
|
||||
let (mut param, mut unprocessed) = pattern.split_at(close_idx + 1);
|
||||
|
|
|
@ -102,6 +102,7 @@ impl Args {
|
|||
match arg {
|
||||
NestedMeta::Lit(syn::Lit::Str(lit)) => match path {
|
||||
None => {
|
||||
let _ = ResourceDef::new(lit.value());
|
||||
path = Some(lit);
|
||||
}
|
||||
_ => {
|
||||
|
@ -114,7 +115,6 @@ impl Args {
|
|||
NestedMeta::Meta(syn::Meta::NameValue(nv)) => {
|
||||
if nv.path.is_ident("name") {
|
||||
if let syn::Lit::Str(lit) = nv.lit {
|
||||
let _ = ResourceDef::new(lit.value());
|
||||
resource_name = Some(lit);
|
||||
} else {
|
||||
return Err(syn::Error::new_spanned(
|
||||
|
|
|
@ -1,7 +1,33 @@
|
|||
use actix_web_codegen::*;
|
||||
use actix_web_codegen::get;
|
||||
|
||||
#[get("/one/{", other)]
|
||||
async fn one() -> String {
|
||||
"Hello World!".to_owned()
|
||||
#[get("/{")]
|
||||
async fn zero() -> &'static str {
|
||||
"malformed resource def"
|
||||
}
|
||||
|
||||
#[get("/{foo")]
|
||||
async fn one() -> &'static str {
|
||||
"malformed resource def"
|
||||
}
|
||||
|
||||
#[get("/{}")]
|
||||
async fn two() -> &'static str {
|
||||
"malformed resource def"
|
||||
}
|
||||
|
||||
#[get("/*")]
|
||||
async fn three() -> &'static str {
|
||||
"malformed resource def"
|
||||
}
|
||||
|
||||
#[get("/{tail:\\d+}*")]
|
||||
async fn four() -> &'static str {
|
||||
"malformed resource def"
|
||||
}
|
||||
|
||||
#[get("/{a}/{b}/{c}/{d}/{e}/{f}/{g}/{h}/{i}/{j}/{k}/{l}/{m}/{n}/{o}/{p}/{q}")]
|
||||
async fn five() -> &'static str {
|
||||
"malformed resource def"
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
|
@ -1,5 +1,42 @@
|
|||
error: Unknown attribute.
|
||||
--> $DIR/route-malformed-path-fail.rs:3:17
|
||||
error: custom attribute panicked
|
||||
--> $DIR/route-malformed-path-fail.rs:3:1
|
||||
|
|
||||
3 | #[get("/one/{", other)]
|
||||
| ^^^^^
|
||||
3 | #[get("/{")]
|
||||
| ^^^^^^^^^^^^
|
||||
|
|
||||
= help: message: pattern "{" contains malformed dynamic segment
|
||||
|
||||
error: custom attribute panicked
|
||||
--> $DIR/route-malformed-path-fail.rs:8:1
|
||||
|
|
||||
8 | #[get("/{foo")]
|
||||
| ^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: message: pattern "{foo" contains malformed dynamic segment
|
||||
|
||||
error: custom attribute panicked
|
||||
--> $DIR/route-malformed-path-fail.rs:13:1
|
||||
|
|
||||
13 | #[get("/{}")]
|
||||
| ^^^^^^^^^^^^^
|
||||
|
|
||||
= help: message: Wrong path pattern: "/{}" regex parse error:
|
||||
((?s-m)^/(?P<>[^/]+))$
|
||||
^
|
||||
error: empty capture group name
|
||||
|
||||
error: custom attribute panicked
|
||||
--> $DIR/route-malformed-path-fail.rs:23:1
|
||||
|
|
||||
23 | #[get("/{tail:\\d+}*")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: message: custom regex is not supported for tail match
|
||||
|
||||
error: custom attribute panicked
|
||||
--> $DIR/route-malformed-path-fail.rs:28:1
|
||||
|
|
||||
28 | #[get("/{a}/{b}/{c}/{d}/{e}/{f}/{g}/{h}/{i}/{j}/{k}/{l}/{m}/{n}/{o}/{p}/{q}")]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
= help: message: Only 16 dynamic segments are allowed, provided: 17
|
||||
|
|
Loading…
Reference in New Issue