Rocket

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit b0f86dcba0629e1ab402c35e1ac2602348aad0d7
parent 56c6a96f6a94ab844a0f571c303d741c7ec668d3
Author: Sergio Benitez <sb@sergio.bz>
Date:   Sun, 29 Jul 2018 18:24:25 -0700

Fix URI normalization checks in 'Rocket::mount()'.

Diffstat:
Mcore/lib/src/rocket.rs | 36+++++++++++++++++++-----------------
Mcore/lib/src/router/route.rs | 1+
Mexamples/todo/src/main.rs | 2+-
3 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/core/lib/src/rocket.rs b/core/lib/src/rocket.rs @@ -499,22 +499,28 @@ impl Rocket { Paint::blue(base)); if base.contains('<') || base.contains('>') { - error_!("Invalid mount point: {}", base); - panic!("Mount points cannot contain dynamic parameters"); + error_!("Mount point '{}' contains dynamic paramters.", base); + panic!("Invalid mount point."); } - for mut route in routes { - let base_uri = Origin::parse(base) - .unwrap_or_else(|e| { - error_!("Invalid origin URI used as mount point: {}", base); - panic!("Error: {}", e); - }); + let base_uri = Origin::parse(base) + .unwrap_or_else(|e| { + error_!("Invalid origin URI '{}' used as mount point.", base); + panic!("Error: {}", e); + }); - if base_uri.query().is_some() { - error_!("Mount point cannot contain a query string: {}", base_uri); - panic!("Invalid mount point."); - } + if base_uri.query().is_some() { + error_!("Mount point '{}' contains query string.", base); + panic!("Invalid mount point."); + } + if !base_uri.is_normalized() { + error_!("Mount point '{}' is not normalized.", base_uri); + info_!("Expected: '{}'.", base_uri.to_normalized()); + panic!("Invalid mount point."); + } + + for mut route in routes { let complete_uri = format!("{}/{}", base_uri, route.uri); let uri = Origin::parse_route(&complete_uri) .unwrap_or_else(|e| { @@ -522,11 +528,7 @@ impl Rocket { panic!("Error: {}", e) }); - if !uri.is_normalized() { - warn_!("Abnormal URI '{}' will be automatically normalized.", uri); - } - - route.set_base(base_uri); + route.set_base(base_uri.clone()); route.set_uri(uri.to_normalized()); info_!("{}", route); diff --git a/core/lib/src/router/route.rs b/core/lib/src/router/route.rs @@ -266,6 +266,7 @@ impl fmt::Debug for Route { #[doc(hidden)] impl<'a> From<&'a StaticRouteInfo> for Route { fn from(info: &'a StaticRouteInfo) -> Route { + // This should never panic since `info.path` is statically checked. let mut route = Route::new(info.method, info.path, info.handler); route.format = info.format.clone(); route.name = Some(info.name); diff --git a/examples/todo/src/main.rs b/examples/todo/src/main.rs @@ -80,7 +80,7 @@ fn rocket() -> (Rocket, Option<db::Conn>) { let rocket = rocket::ignite() .manage(pool) .mount("/", routes![index, static_files::all]) - .mount("/todo/", routes![new, toggle, delete]) + .mount("/todo", routes![new, toggle, delete]) .attach(Template::fairing()); (rocket, conn)