Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
validate / validate-mimeOpenRuns on Liberas

MIME type (WHATWG)

Parses input by the WHATWG MIME Sniffing Standard's "parse a MIME type" (section 4.4) and serializes the result (4.5). HTTP whitespace: LF, CR, TAB, SPACE. Token code points: ASCII alphanumerics and !#$%&'*+-.^_`|~. Quoted-string token code points: TAB, U+0020-U+007E, U+0080-U+00FF. Strip leading and trailing HTTP whitespace. type is everything before the first /, which must exist; subtype runs to the next ; with trailing HTTP whitespace removed; both must be non-empty and only token code points, else none; both are ASCII lowercased. Then, while input remains: skip the ; and any HTTP whitespace; name runs to the next ; or = and is ASCII lowercased; at a ; start over; skip the =; at the end stop. A value starting with " is an HTTP quoted string (a backslash takes the next code point as is, a backslash at the end stays, the next unescaped " or the end closes it), and whatever follows up to the next ; is ignored; any other value runs to the next ;, trailing HTTP whitespace removed, and when empty the parameter is skipped. A parameter is kept only when its name is non-empty and only token code points, its value only quoted-string token code points, and no earlier kept parameter has its name. essence is type/subtype. serialized is essence then, for each parameter, ; name = value, the value as is when non-empty and only token code points, else in double quotes with a backslash before each " and \. Input over 65,536 bytes is none. web-platform-tests mimesniff/mime-types is the test of record.

From your terminal

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

world root {
  export liberas:validate/mime@0.1.0;
}
package liberas:validate@0.1.0 {
  interface mime {
    record parameter {
      name: string,
      value: string,
    }

    record mime-type {
      %type: string,
      subtype: string,
      essence: string,
      parameters: list<parameter>,
      serialized: string,
    }

    parse: func(input: string) -> option<mime-type>;
  }
}
Test vectors50›
validate-mime.cases.json
[
  {
    "args": {
      "input": "text/html;charset=gbk"
    }
  },
  {
    "args": {
      "input": "TEXT/HTML;CHARSET=GBK"
    }
  },
  {
    "args": {
      "input": "text/html;charset=gbk("
    }
  },
  {
    "args": {
      "input": "text/html;x=(;charset=gbk"
    }
  },
  {
    "args": {
      "input": "text/html;charset=gbk;charset=windows-1255"
    }
  },
  {
    "args": {
      "input": "text/html;charset=();charset=GBK"
    }
  },
  {
    "args": {
      "input": "text/html;charset =gbk"
    }
  },
  {
    "args": {
      "input": "text/html ;charset=gbk"
    }
  },
  {
    "args": {
      "input": "text/html; charset=gbk"
    }
  },
  {
    "args": {
      "input": "text/html;charset= gbk"
    }
  },
  {
    "args": {
      "input": "text/html;charset= \"gbk\""
    }
  },
  {
    "args": {
      "input": "text/html;charset=\"gbk\""
    }
  },
  {
    "args": {
      "input": "text/html;charset=\"gbk"
    }
  },
  {
    "args": {
      "input": "text/html;charset=gbk\""
    }
  },
  {
    "args": {
      "input": "text/html;charset=\"\\g\\b\\k\""
    }
  },
  {
    "args": {
      "input": "text/html;charset=\"gbk\"x"
    }
  },
  {
    "args": {
      "input": "text/html;charset=\"\";charset=GBK"
    }
  },
  {
    "args": {
      "input": "text/html;charset=\";charset=GBK"
    }
  },
  {
    "args": {
      "input": "text/html;charset=\"\\\""
    }
  },
  {
    "args": {
      "input": "text/html;test;charset=gbk"
    }
  },
  {
    "args": {
      "input": "text/html;test=;charset=gbk"
    }
  },
  {
    "args": {
      "input": "text/html;';charset=gbk"
    }
  },
  {
    "args": {
      "input": "text/html;\";charset=gbk"
    }
  },
  {
    "args": {
      "input": "text/html;charset=';charset=GBK"
    }
  },
  {
    "args": {
      "input": "text/html;a=\"\\\"\";b=c"
    }
  },
  {
    "args": {
      "input": "text/html;a=\"b;c\";d=e"
    }
  },
  {
    "args": {
      "input": "text/html;a=b c"
    }
  },
  {
    "args": {
      "input": "text/html;charset=ÿ"
    }
  },
  {
    "args": {
      "input": "text/html;charset=Ā;a=b"
    }
  },
  {
    "args": {
      "input": "x/x;test"
    }
  },
  {
    "args": {
      "input": "x/x;x= "
    }
  },
  {
    "args": {
      "input": "x/x;x=\t"
    }
  },
  {
    "args": {
      "input": "x/x\n\r\t ;x=x"
    }
  },
  {
    "args": {
      "input": "\n\r\t x/x;x=x\n\r\t "
    }
  },
  {
    "args": {
      "input": "\u000bx/x"
    }
  },
  {
    "args": {
      "input": "x/x\f"
    }
  },
  {
    "args": {
      "input": "/html"
    }
  },
  {
    "args": {
      "input": "text/"
    }
  },
  {
    "args": {
      "input": "text"
    }
  },
  {
    "args": {
      "input": "te xt/plain"
    }
  },
  {
    "args": {
      "input": "text/pl ain"
    }
  },
  {
    "args": {
      "input": "text/html;"
    }
  },
  {
    "args": {
      "input": "text/html;;;a=b;"
    }
  },
  {
    "args": {
      "input": "image/svg+xml"
    }
  },
  {
    "args": {
      "input": "application/vnd.api+json; Charset=UTF-8"
    }
  },
  {
    "args": {
      "input": "*/*"
    }
  },
  {
    "args": {
      "input": "text/plain;a=\"\""
    }
  },
  {
    "args": {
      "input": "text/plain;a=\"b c\";b=\"d\\\\e\""
    }
  },
  {
    "args": {
      "input": "ἀ/b"
    }
  },
  {
    "args": {
      "input": ""
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 50 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 110,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.