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

Form URL-encoded serialize

pairs serialized as the WHATWG URL Standard's application/x-www-form-urlencoded serializer does it with UTF-8: each name and value is encoded byte by byte, ASCII letters, digits and *-._ kept, a space written '+', every other byte written %XX with uppercase hex; each pair is written name=value (the '=' even when value is empty) and pairs are joined by '&'; no pairs give empty text. More than 1,048,576 UTF-8 bytes of names and values in all 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-serialize --lang rust
cd data-urlencoded-serialize && 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-serialize.wit
package root:component;

world root {
  export liberas:data/urlencoded-write@0.1.0;
}
package liberas:data@0.1.0 {
  interface urlencoded-write {
    serialize: func(pairs: list<tuple<string, string>>) -> result<string, string>;
  }
}
Test vectors8›
data-urlencoded-serialize.cases.json
[
  {
    "args": {
      "pairs": [
        [
          "a",
          "1"
        ],
        [
          "b",
          "2"
        ]
      ]
    }
  },
  {
    "args": {
      "pairs": [
        [
          "a b",
          "c d+e"
        ]
      ]
    }
  },
  {
    "args": {
      "pairs": [
        [
          "*-._~",
          "!'()&="
        ]
      ]
    }
  },
  {
    "args": {
      "pairs": [
        [
          "é",
          "€😀"
        ]
      ]
    }
  },
  {
    "args": {
      "pairs": [
        [
          "",
          ""
        ]
      ]
    }
  },
  {
    "args": {
      "pairs": []
    }
  },
  {
    "args": {
      "pairs": [
        [
          "q",
          "%20"
        ],
        [
          "\u0001",
          ""
        ]
      ]
    }
  },
  {
    "args": {
      "pairs": [
        [
          "Hello World",
          "x/y?z#w"
        ],
        [
          "a",
          ""
        ]
      ]
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 8 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 1,000,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.