File: encode_selectively.js

package info (click to toggle)
mozjs128 128.14.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,132,528 kB
  • sloc: javascript: 2,181,430; cpp: 1,371,420; python: 776,651; ansic: 641,398; xml: 117,736; sh: 17,537; asm: 13,468; makefile: 11,191; yacc: 4,504; perl: 2,221; lex: 1,414; ruby: 1,032; exp: 756; java: 185; sql: 66; sed: 18
file content (23 lines) | stat: -rw-r--r-- 1,204 bytes parent folder | download | duplicates (16)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
* AUTO-GENERATED - DO NOT EDIT. Source: https://github.com/gpuweb/cts
**/ /**
 * Encodes a stringified TestQuery so that it can be placed in a `?q=` parameter in a URL.
 *
 * `encodeURIComponent` encodes in accordance with `application/x-www-form-urlencoded`,
 * but URLs don't actually have to be as strict as HTML form encoding
 * (we interpret this purely from JavaScript).
 * So we encode the component, then selectively convert some %-encoded escape codes
 * back to their original form for readability/copyability.
 */export function encodeURIComponentSelectively(s) {let ret = encodeURIComponent(s);
  ret = ret.replace(/%22/g, '"'); // for JSON strings
  ret = ret.replace(/%2C/g, ','); // for path separator, and JSON arrays
  ret = ret.replace(/%3A/g, ':'); // for big separator
  ret = ret.replace(/%3B/g, ';'); // for param separator
  ret = ret.replace(/%3D/g, '='); // for params (k=v)
  ret = ret.replace(/%5B/g, '['); // for JSON arrays
  ret = ret.replace(/%5D/g, ']'); // for JSON arrays
  ret = ret.replace(/%7B/g, '{'); // for JSON objects
  ret = ret.replace(/%7D/g, '}'); // for JSON objects
  ret = ret.replace(/%E2%9C%97/g, '✗'); // for jsUndefinedMagicValue
  return ret;
}