Warn, but don't error, on unknown route formats.

Partially fixes #66.
This commit is contained in:
Sergio Benitez 2016-12-27 15:30:33 -06:00
parent 3d0f7f2f80
commit 9da512c60c
4 changed files with 69 additions and 4 deletions

View File

@ -272,15 +272,15 @@ fn parse_format(ecx: &ExtCtxt, kv: &KVSpanned<LitKind>) -> ContentType {
if !ct.is_known() {
let msg = format!("'{}' is not a known content-type", s);
ecx.span_warn(kv.value.span, &msg);
} else {
return ct;
}
return ct;
} 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
the key is `format` and the value is a string representing the
content-type accepted. e.g: format = "application/json""#)

View File

@ -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() { }

View File

@ -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() { }

View File

@ -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() { }