Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
data / data-urlencoded-parseOpenRuns on Liberas

Form URL-encoded parse

The name-value pairs of input as the WHATWG URL Standard's application/x-www-form-urlencoded parser yields them, in order: input's UTF-8 bytes are split on '&'; empty pieces are skipped; each piece is split at its first '=' (none: the whole piece is the name and the value is empty); in both parts '+' becomes a space, then each '%' followed by two hex digits (either case) becomes that byte, any other '%' staying as is; the bytes are decoded as UTF-8 with each maximal invalid subsequence replaced by U+FFFD and a leading BOM kept. input of more than 1,048,576 UTF-8 bytes is an error; nothing else is.

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init data-urlencoded-parse --lang rust
cd data-urlencoded-parse && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)11 lines›
data-urlencoded-parse.wit
package root:component;

world root {
  export liberas:data/urlencoded-read@0.1.0;
}
package liberas:data@0.1.0 {
  interface urlencoded-read {
    parse: func(input: string) -> result<list<tuple<string, string>>, string>;
  }
}
Test vectors10›
data-urlencoded-parse.cases.json
[
  {
    "args": {
      "input": "a=1&b=2"
    }
  },
  {
    "args": {
      "input": "a+b=c%20d+%2B"
    }
  },
  {
    "args": {
      "input": "&&a&=b&c=&&"
    }
  },
  {
    "args": {
      "input": "a=b=c&=="
    }
  },
  {
    "args": {
      "input": "%zz=%4&x=%"
    }
  },
  {
    "args": {
      "input": "%C3%A9=%c3%a9&%E2%82%AC=€"
    }
  },
  {
    "args": {
      "input": "%EF%BF=%80%FFx&%F0%9F%98=%ED%A0%80"
    }
  },
  {
    "args": {
      "input": "%EF%BB%BFa=1"
    }
  },
  {
    "args": {
      "input": ""
    }
  },
  {
    "args": {
      "input": "q=%26%3D%25&%00=%7F"
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 10 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • A remote call may execute up to 2,000,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.