MCPcopy Index your code
hub / github.com/nodejs/node / percentDecode

Function percentDecode

lib/internal/data_url.js:219–258  ·  view source on GitHub ↗

* @param {Uint8Array} input * @returns {Uint8Array}

(input)

Source from the content-addressed store, hash-verified

217 * @returns {Uint8Array}
218 */
219function percentDecode(input) {
220 const length = input.length;
221 // 1. Let output be an empty byte sequence.
222 /** @type {Uint8Array} */
223 const output = new Uint8Array(length);
224 let j = 0;
225 // 2. For each byte byte in input:
226 for (let i = 0; i < length; ++i) {
227 const byte = input[i];
228
229 // 1. If byte is not 0x25 (%), then append byte to output.
230 if (byte !== 0x25) {
231 output[j++] = byte;
232
233 // 2. Otherwise, if byte is 0x25 (%) and the next two bytes
234 // after byte in input are not in the ranges
235 // 0x30 (0) to 0x39 (9), 0x41 (A) to 0x46 (F),
236 // and 0x61 (a) to 0x66 (f), all inclusive, append byte
237 // to output.
238 } else if (
239 byte === 0x25 &&
240 !(isHexCharByte(input[i + 1]) && isHexCharByte(input[i + 2]))
241 ) {
242 output[j++] = 0x25;
243
244 // 3. Otherwise:
245 } else {
246 // 1. Let bytePoint be the two bytes after byte in input,
247 // decoded, and then interpreted as hexadecimal number.
248 // 2. Append a byte whose value is bytePoint to output.
249 output[j++] = (hexByteToNumber(input[i + 1]) << 4) | hexByteToNumber(input[i + 2]);
250
251 // 3. Skip the next two bytes in input.
252 i += 2;
253 }
254 }
255
256 // 3. Return output.
257 return length === j ? output : TypedArrayPrototypeSubarray(output, 0, j);
258}
259
260// https://infra.spec.whatwg.org/#forgiving-base64-decode
261/**

Callers 3

stringPercentDecodeFunction · 0.70

Calls 2

isHexCharByteFunction · 0.70
hexByteToNumberFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…