Check mount point validity in 'uri!' macro.

This commit is contained in:
Sergio Benitez 2017-09-11 01:22:26 -07:00
parent d8acd04789
commit 24f7734c00
2 changed files with 10 additions and 2 deletions

View File

@ -78,6 +78,12 @@ impl UriParams {
Some((symbol, _, _)) => {
let string = symbol.as_str();
let span = parser.prev_span;
if string.contains('<') || !string.starts_with('/') {
let mut diag = ecx.struct_span_err(span, "invalid mount point");
diag.help("mount points must be static, absolute URIs: `/example`");
return Err(diag);
}
parser.expect(&Token::Comma)?;
Some(span.wrap(string))
}

View File

@ -12,8 +12,10 @@ fn main() {
uri!(simple: "Hello", id = 100); //~ ERROR cannot be mixed
uri!(simple,); //~ ERROR expected one of `::`, `:`, or `<eof>`
uri!(simple:); //~ ERROR expected argument list
uri!("mount"); //~ ERROR expected `,`, found `<eof>`
uri!("mount",); //~ ERROR expected identifier
uri!("/mount"); //~ ERROR expected `,`, found `<eof>`
uri!("/mount",); //~ ERROR expected identifier
uri!("mount", simple); //~ ERROR invalid mount point
uri!("/mount/<id>", simple); //~ ERROR invalid mount point
uri!(); //~ ERROR cannot be empty
uri!(simple: id = ); //~ ERROR expected argument list
//~^ ERROR expected expression