mirror of
https://github.com/rwf2/Rocket.git
synced 2025-01-08 10:42:37 +00:00
ed429cd487
This commit changes the way Rocket parses form items. In particular, it now (liberally) validates form strings, returning a Bad Request on malformed inputs and Unprocessable Entity on bad parses. The 'FormItems' iterator was modified to accomodate this. The iterator is now initialized using 'from': 'FormItems::from(form_string)'. The iterator can be queried to check for a complete parse using either 'completed()' or 'exhausted()', the latter of which will consume valid keys/values and return true only if the entire string was consumed. The 'FromForm' trait now takes a mutable borrow to a 'FormItems' iterator. The 'Form' and 'FormForm' implementation for 'Form' were modified to use the new iterfaces and check for 'exhausted' after a parse, returning a Bad Request error if the iterator cannot be exhausted. Resolves #46.
16 lines
346 B
Rust
16 lines
346 B
Rust
#![feature(plugin, custom_derive)]
|
|
#![plugin(rocket_codegen)]
|
|
|
|
extern crate rocket;
|
|
|
|
use rocket::request::{FromForm, FormItems};
|
|
|
|
#[derive(PartialEq, Debug, FromForm)]
|
|
struct Form { }
|
|
|
|
fn main() {
|
|
// Same number of arguments: simple case.
|
|
let task = Form::from_form_items(&mut FormItems::from(""));
|
|
assert_eq!(task, Ok(Form { }));
|
|
}
|