mirror of https://github.com/rwf2/Rocket.git
Disallow use of data parameter with non-payload methods.
This commit is contained in:
parent
fb67681adc
commit
25d55b4b0f
|
@ -104,6 +104,16 @@ impl RouteParams {
|
|||
}
|
||||
}
|
||||
|
||||
// Sanity check: `data` should only be used with payload methods.
|
||||
if let Some(ref data_param) = data {
|
||||
if !method.node.supports_payload() {
|
||||
ecx.struct_span_err(data_param.span, "`data` route parameters \
|
||||
can only be used with payload supporting methods")
|
||||
.note(&format!("'{}' does not support payloads", method.node))
|
||||
.emit();
|
||||
}
|
||||
}
|
||||
|
||||
RouteParams {
|
||||
method: method,
|
||||
path: path,
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
#![feature(plugin)]
|
||||
#![plugin(rocket_codegen)]
|
||||
|
||||
extern crate rocket;
|
||||
|
||||
use rocket::Data;
|
||||
|
||||
#[get("/", data = "<something>")]
|
||||
//~^ ERROR payload supporting methods
|
||||
fn get(something: Data) -> &'static str { "hi" }
|
||||
|
||||
fn main() { }
|
|
@ -7,7 +7,7 @@ fn get(other: &str) -> &'static str { "hi" } //~ ERROR isn't in the function
|
|||
#[get("/a?<r>")] //~ ERROR 'r' is declared
|
||||
fn get1() -> &'static str { "hi" } //~ ERROR isn't in the function
|
||||
|
||||
#[get("/a", data = "<test>")] //~ ERROR 'test' is declared
|
||||
fn get2() -> &'static str { "hi" } //~ ERROR isn't in the function
|
||||
#[post("/a", data = "<test>")] //~ ERROR 'test' is declared
|
||||
fn post() -> &'static str { "hi" } //~ ERROR isn't in the function
|
||||
|
||||
fn main() { }
|
||||
|
|
|
@ -7,9 +7,9 @@ use http::hyper::{header, FreshHyperResponse, StatusCode};
|
|||
use outcome::{self, IntoOutcome};
|
||||
use outcome::Outcome::*;
|
||||
|
||||
/// Type alias for the `Outcome` of a `Responder`.
|
||||
pub type Outcome<'a> = outcome::Outcome<(), (), (StatusCode, FreshHyperResponse<'a>)>;
|
||||
|
||||
|
||||
impl<'a, T, E> IntoOutcome<(), (), (StatusCode, FreshHyperResponse<'a>)> for Result<T, E> {
|
||||
fn into_outcome(self) -> Outcome<'a> {
|
||||
match self {
|
||||
|
|
Loading…
Reference in New Issue