Reference

std/uri/form

std/uri/src/form.trb

application/x-www-form-urlencoded, the convention of HTML forms for a query and for a form body, as the WHATWG URL Standard (section 5) defines it. It is not part of RFC 3986, which leaves a query opaque; that is why the URI types hold the query as text and read it through these two functions only when asked (docs/design/URI.md section 5).

fn formDecoded

fn formDecoded(text: String): List<(String, String)>

A form read into its pairs, in order: split at &, each part at its first =, + read as a space, escapes decoded, and the bytes read as UTF-8 with U+FFFD for what is not. Empty parts are skipped and a part without = has the value "". Nothing fails: this is the standard's parser, which a browser applies to whatever it is handed.

Examples

print formDecoded("name=Ada+Lovelace&tag=a&tag=b&flag")

fn formEncoded

fn formEncoded(pairs: List<(String, String)>): String

Pairs written as a form: every byte but ASCII letters, digits, *, -, . and _ percent-encoded, a space as +, = between a name and its value and & between the pairs. This is the standard's serializer, so what a browser would send for the same fields is what comes out.

Examples

print formEncoded([("q", "GrĂ¼ner Weg"), ("page", "2")])