MCPcopy Create free account
hub / github.com/angular/dev-infra / dataURLProcessor

Function dataURLProcessor

github-actions/browserstack/set-browserstack-env.js:3454–3490  ·  view source on GitHub ↗
(dataURL)

Source from the content-addressed store, hash-verified

3452 var require_data_url = __commonJS({
3453 ""(exports, module) {
3454 "use strict";
3455 var assert = __require("assert");
3456 var encoder = new TextEncoder();
3457 var HTTP_TOKEN_CODEPOINTS = /^[!#$%&'*+\-.^_|~A-Za-z0-9]+$/;
3458 var HTTP_WHITESPACE_REGEX = /[\u000A\u000D\u0009\u0020]/;
3459 var ASCII_WHITESPACE_REPLACE_REGEX = /[\u0009\u000A\u000C\u000D\u0020]/g;
3460 var HTTP_QUOTED_STRING_TOKENS = /^[\u0009\u0020-\u007E\u0080-\u00FF]+$/;
3461 function dataURLProcessor(dataURL) {
3462 assert(dataURL.protocol === "data:");
3463 let input = URLSerializer(dataURL, true);
3464 input = input.slice(5);
3465 const position = { position: 0 };
3466 let mimeType = collectASequenceOfCodePointsFast(
3467 ",",
3468 input,
3469 position
3470 );
3471 const mimeTypeLength = mimeType.length;
3472 mimeType = removeASCIIWhitespace(mimeType, true, true);
3473 if (position.position >= input.length) {
3474 return "failure";
3475 }
3476 position.position++;
3477 const encodedBody = input.slice(mimeTypeLength + 1);
3478 let body = stringPercentDecode(encodedBody);
3479 if (/;(\u0020){0,}base64$/i.test(mimeType)) {
3480 const stringBody = isomorphicDecode(body);
3481 body = forgivingBase64(stringBody);
3482 if (body === "failure") {
3483 return "failure";
3484 }
3485 mimeType = mimeType.slice(0, -6);
3486 mimeType = mimeType.replace(/(\u0020)+$/, "");
3487 mimeType = mimeType.slice(0, -1);
3488 }
3489 if (mimeType.startsWith(";")) {
3490 mimeType = "text/plain" + mimeType;
3491 }
3492 let mimeTypeRecord = parseMIMEType(mimeType);
3493 if (mimeTypeRecord === "failure") {

Callers 1

schemeFetchFunction · 0.70

Calls 8

URLSerializerFunction · 0.70
removeASCIIWhitespaceFunction · 0.70
stringPercentDecodeFunction · 0.70
isomorphicDecodeFunction · 0.70
forgivingBase64Function · 0.70
parseMIMETypeFunction · 0.70
sliceMethod · 0.45

Tested by

no test coverage detected