mirror of https://github.com/rwf2/Rocket.git
parent
3d0f7f2f80
commit
9da512c60c
|
@ -272,15 +272,15 @@ fn parse_format(ecx: &ExtCtxt, kv: &KVSpanned<LitKind>) -> ContentType {
|
||||||
if !ct.is_known() {
|
if !ct.is_known() {
|
||||||
let msg = format!("'{}' is not a known content-type", s);
|
let msg = format!("'{}' is not a known content-type", s);
|
||||||
ecx.span_warn(kv.value.span, &msg);
|
ecx.span_warn(kv.value.span, &msg);
|
||||||
} else {
|
|
||||||
return ct;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ct;
|
||||||
} else {
|
} else {
|
||||||
ecx.span_err(kv.value.span, "malformed content type");
|
ecx.span_err(kv.value.span, "malformed content-type");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ecx.struct_span_err(kv.span, r#"`format` must be a "content/type"`"#)
|
ecx.struct_span_err(kv.span, r#"`format` must be a "content/type""#)
|
||||||
.help(r#"format, if specified, must be a key-value pair where
|
.help(r#"format, if specified, must be a key-value pair where
|
||||||
the key is `format` and the value is a string representing the
|
the key is `format` and the value is a string representing the
|
||||||
content-type accepted. e.g: format = "application/json""#)
|
content-type accepted. e.g: format = "application/json""#)
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
#![feature(plugin)]
|
||||||
|
#![plugin(rocket_codegen)]
|
||||||
|
|
||||||
|
extern crate rocket;
|
||||||
|
|
||||||
|
#[get("/", format = "applicationx-custom")] //~ ERROR malformed
|
||||||
|
//~^ ERROR `format` must be a "content/type"
|
||||||
|
fn one() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
#[get("/", format = "")] //~ ERROR malformed
|
||||||
|
//~^ ERROR `format` must be a "content/type"
|
||||||
|
fn two() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
#[get("/", format = "//")] //~ ERROR malformed
|
||||||
|
//~^ ERROR `format` must be a "content/type"
|
||||||
|
fn three() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
#[get("/", format = "/")] //~ ERROR malformed
|
||||||
|
//~^ ERROR `format` must be a "content/type"
|
||||||
|
fn four() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
#[get("/", format = "a/")] //~ ERROR malformed
|
||||||
|
//~^ ERROR `format` must be a "content/type"
|
||||||
|
fn five() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
#[get("/", format = "/a")] //~ ERROR malformed
|
||||||
|
//~^ ERROR `format` must be a "content/type"
|
||||||
|
fn six() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
#[get("/", format = "/a/")] //~ ERROR malformed
|
||||||
|
//~^ ERROR `format` must be a "content/type"
|
||||||
|
fn seven() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
#[get("/", format = "a/b/")] //~ ERROR malformed
|
||||||
|
//~^ ERROR `format` must be a "content/type"
|
||||||
|
fn eight() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
fn main() { }
|
|
@ -0,0 +1,18 @@
|
||||||
|
#![feature(plugin)]
|
||||||
|
#![plugin(rocket_codegen)]
|
||||||
|
|
||||||
|
extern crate rocket;
|
||||||
|
|
||||||
|
#[get("/", format = "application/x-custom")] //~ WARNING not a known content-type
|
||||||
|
fn one() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
#[get("/", format = "x-custom/plain")] //~ WARNING not a known content-type
|
||||||
|
fn two() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
#[get("/", format = "x-custom/x-custom")] //~ WARNING not a known content-type
|
||||||
|
fn three() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
// Make the test fail here so we can actually check for the warnings above.
|
||||||
|
assert!(false);
|
||||||
|
|
||||||
|
fn main() { }
|
|
@ -0,0 +1,9 @@
|
||||||
|
#![feature(plugin, custom_derive)]
|
||||||
|
#![plugin(rocket_codegen)]
|
||||||
|
|
||||||
|
extern crate rocket;
|
||||||
|
|
||||||
|
#[post("/", format = "application/x-custom")]
|
||||||
|
fn get() -> &'static str { "hi" }
|
||||||
|
|
||||||
|
fn main() { }
|
Loading…
Reference in New Issue