Rocket/core/codegen/tests/ui-fail/route-path-bad-syntax.rs
Sergio Benitez 0a56312607 Implement more conservative URI normalization.
* Trailing slashes are now allowed in all normalized URI paths, except
    for route attribute URIs: `/foo/` is considered normalized.
  * Query parts of URIs may now be empty: `/foo?` and `/foo/?` are now
    considered normalized.
  * The `base` field of `Catcher` is now only accessible via a new
    getter method: `Catcher::base()`.
  * `RawStr::split()` returns a `DoubleEndedIterator`.
  * Introduced a second normalization for `Origin`, "nontrailing", and
    associated methods: `Origin::normalize_nontrailing()`, and
    `Origin::is_normalized_nontrailing()`.
  * Added `Origin::has_trailing_slash()`.
  * The `Segments<Path>` iterator will now return an empty string if
    there is a trailing slash in the referenced path.
  * `Segments::len()` is now `Segments::num()`.
  * Added `RawStr::trim()`.

Resolves #2512.
2023-04-07 19:59:57 -07:00

117 lines
1.5 KiB
Rust

#[macro_use] extern crate rocket;
// Check that route paths are absolute and normalized.
#[get("a")]
fn f0() {}
#[get("")]
fn f1() {}
#[get("a/b/c")]
fn f2() {}
#[get("/a///b")]
fn f3() {}
#[get("/?bat&&")]
fn f4() {}
#[get("/?bat&&")]
fn f5() {}
#[get("/a/b//")]
fn f6() {}
// Check that paths contain only valid URI characters
#[get("/!@#$%^&*()")]
fn g1() {}
#[get("/a%20b")]
fn g2() {}
#[get("/a?a%20b")]
fn g3() {}
#[get("/a?a+b")]
fn g4() {}
// Check that all declared parameters are accounted for
#[get("/<name>")]
fn h0(_name: usize) {}
#[get("/a?<r>")]
fn h1() {}
#[post("/a", data = "<test>")]
fn h2() {}
#[get("/<_r>")]
fn h3() {}
#[get("/<_r>/<b>")]
fn h4() {}
//
// Check dynamic parameters are valid idents
#[get("/<foo_.>")]
fn i0() {}
#[get("/<foo*>")]
fn i1() {}
#[get("/<!>")]
fn i2() {}
#[get("/<name>:<id>")]
fn i3() {}
// Check that a data parameter is exactly `<param>`
#[get("/", data = "foo")]
fn j0() {}
#[get("/", data = "<foo..>")]
fn j1() {}
#[get("/", data = "<foo")]
fn j2() {}
#[get("/", data = "<test >")]
fn j3() {}
// Check that all identifiers are named
#[get("/<_>")]
fn k0(_: usize) {}
// Check that strange dynamic syntax is caught.
#[get("/<>")]
fn m0() {}
#[get("/<id><")]
fn m1() {}
#[get("/<<<<id><")]
fn m2() {}
#[get("/<>name><")]
fn m3() {}
// New additions for trailing paths, which we artificially disallow.
#[get("/a/")]
fn n1() {}
#[get("/a/b/")]
fn n2() {}
#[get("/a/b/c/")]
fn n3() {}
fn main() { }