Debian Codegraph @

testing/web-platform/mozilla/tests/webgpu/common/internal/query/encode_selectively.js

raw
1 /**
2 * AUTO-GENERATED - DO NOT EDIT. Source: https://github.com/gpuweb/cts
3 **/ /**
4 * Encodes a stringified TestQuery so that it can be placed in a `?q=` parameter in a URL.
5 *
6 * `encodeURIComponent` encodes in accordance with `application/x-www-form-urlencoded`,
7 * but URLs don't actually have to be as strict as HTML form encoding
8 * (we interpret this purely from JavaScript).
9 * So we encode the component, then selectively convert some %-encoded escape codes
10 * back to their original form for readability/copyability.
11 */export function encodeURIComponentSelectively(s) {let ret = encodeURIComponent(s);
12 ret = ret.replace(/%22/g, '"'); // for JSON strings
13 ret = ret.replace(/%2C/g, ','); // for path separator, and JSON arrays
14 ret = ret.replace(/%3A/g, ':'); // for big separator
15 ret = ret.replace(/%3B/g, ';'); // for param separator
16 ret = ret.replace(/%3D/g, '='); // for params (k=v)
17 ret = ret.replace(/%5B/g, '['); // for JSON arrays
18 ret = ret.replace(/%5D/g, ']'); // for JSON arrays
19 ret = ret.replace(/%7B/g, '{'); // for JSON objects
20 ret = ret.replace(/%7D/g, '}'); // for JSON objects
21 ret = ret.replace(/%E2%9C%97/g, '✗'); // for jsUndefinedMagicValue
22 return ret;
23 }