mirror of
https://github.com/fafhrd91/actix-web
synced 2025-06-25 06:39:22 +02:00
compile time validation of path (#2350)
* compile time validation of path * added trybuild err message * Update Cargo.toml * add changelog entry * test more cases of path validation * fmt Co-authored-by: Rob Ede <robjtede@icloud.com>
This commit is contained in:
committed by
GitHub
parent
4bb32fb19b
commit
168b2f227d
@ -10,6 +10,7 @@ fn compile_macros() {
|
||||
t.compile_fail("tests/trybuild/route-missing-method-fail.rs");
|
||||
t.compile_fail("tests/trybuild/route-duplicate-method-fail.rs");
|
||||
t.compile_fail("tests/trybuild/route-unexpected-method-fail.rs");
|
||||
t.compile_fail("tests/trybuild/route-malformed-path-fail.rs");
|
||||
|
||||
t.pass("tests/trybuild/docstring-ok.rs");
|
||||
}
|
||||
|
@ -0,0 +1,33 @@
|
||||
use actix_web_codegen::get;
|
||||
|
||||
#[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() {}
|
@ -0,0 +1,42 @@
|
||||
error: custom attribute panicked
|
||||
--> $DIR/route-malformed-path-fail.rs:3:1
|
||||
|
|
||||
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
|
Reference in New Issue
Block a user