Skip to main content

parse_urlencoded

Function parse_urlencoded 

Source
pub fn parse_urlencoded(input: &[u8]) -> Result<Form, FormError>
Available on crate feature alloc only.
Expand description

Parses a whole application/x-www-form-urlencoded body with the default limits and policy, and returns the fields, owned, in input order.

& is the only separator (; is an ordinary byte), + is a space, and a malformed % or invalid UTF-8 is refused, never repaired.

§Errors

Limit { Body | Fields | NameLength | ValueLength | TextTotal }; Encoding { InvalidPercent | InvalidUtf8 }.

§Examples

let form = form_net::parse_urlencoded(b"email=a%40b.example&remember=on")?;
assert_eq!(form.get("email"), Some("a@b.example"));
assert_eq!(form.get("remember"), Some("on"));

let form = form_net::parse_urlencoded(b"a=1;b=2")?;
assert_eq!(form.get("a"), Some("1;b=2"));

assert!(form_net::parse_urlencoded(b"name=%zz").is_err());
assert!(form_net::parse_urlencoded(b"name=%C0%AF").is_err());