Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
encode / encode-percent-decodeOpenRuns on Liberas

Percent-decode

Decodes percent-encoding (RFC 3986 §2.1): each "%" must be followed by two hex digits (0–9, a–f, A–F) and stands for that byte; a "%" not followed by two hex digits, including one at the end, is an error. Every other character, reserved or not, is kept as its UTF-8 bytes unchanged ("+" stays "+", not a space). The result need not be valid UTF-8 ("%FF" → the byte 0xFF). The empty string decodes to no bytes. text is a string of at most 16 MiB (16,777,216 bytes of UTF-8); more is an error. The result is bytes (base64 in JSON).

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init encode-percent-decode --lang rust
cd encode-percent-decode && 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›
encode-percent-decode.wit
package root:component;

world root {
  export liberas:encode/decoder@0.1.0;
}
package liberas:encode@0.1.0 {
  interface decoder {
    decode: func(text: string) -> result<list<u8>, string>;
  }
}
Test vectors17›
encode-percent-decode.cases.json
[
  {
    "args": {
      "text": ""
    }
  },
  {
    "args": {
      "text": "abc"
    }
  },
  {
    "args": {
      "text": "a%20b"
    }
  },
  {
    "args": {
      "text": "%2f%2F"
    }
  },
  {
    "args": {
      "text": "a+b"
    }
  },
  {
    "args": {
      "text": "%FF%00"
    }
  },
  {
    "args": {
      "text": "%C3%BC"
    }
  },
  {
    "args": {
      "text": "한글 🙂"
    }
  },
  {
    "args": {
      "text": "100%25"
    }
  },
  {
    "args": {
      "text": "/?#[]@"
    }
  },
  {
    "args": {
      "text": "%"
    }
  },
  {
    "args": {
      "text": "%2"
    }
  },
  {
    "args": {
      "text": "%G0"
    }
  },
  {
    "args": {
      "text": "%%"
    }
  },
  {
    "args": {
      "text": "abc%2"
    }
  },
  {
    "args": {
      "text": "%-1"
    }
  },
  {
    "args": {
      "text": "% 20"
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 17 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,200,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.