@param {URL} dataURL
(dataURL)
| 19 | // https://fetch.spec.whatwg.org/#data-url-processor |
| 20 | /** @param {URL} dataURL */ |
| 21 | function dataURLProcessor (dataURL) { |
| 22 | // 1. Assert: dataURL’s scheme is "data". |
| 23 | assert(dataURL.protocol === 'data:') |
| 24 | |
| 25 | // 2. Let input be the result of running the URL |
| 26 | // serializer on dataURL with exclude fragment |
| 27 | // set to true. |
| 28 | let input = URLSerializer(dataURL, true) |
| 29 | |
| 30 | // 3. Remove the leading "data:" string from input. |
| 31 | input = input.slice(5) |
| 32 | |
| 33 | // 4. Let position point at the start of input. |
| 34 | const position = { position: 0 } |
| 35 | |
| 36 | // 5. Let mimeType be the result of collecting a |
| 37 | // sequence of code points that are not equal |
| 38 | // to U+002C (,), given position. |
| 39 | let mimeType = collectASequenceOfCodePointsFast( |
| 40 | ',', |
| 41 | input, |
| 42 | position |
| 43 | ) |
| 44 | |
| 45 | // 6. Strip leading and trailing ASCII whitespace |
| 46 | // from mimeType. |
| 47 | // Undici implementation note: we need to store the |
| 48 | // length because if the mimetype has spaces removed, |
| 49 | // the wrong amount will be sliced from the input in |
| 50 | // step #9 |
| 51 | const mimeTypeLength = mimeType.length |
| 52 | mimeType = removeASCIIWhitespace(mimeType, true, true) |
| 53 | |
| 54 | // 7. If position is past the end of input, then |
| 55 | // return failure |
| 56 | if (position.position >= input.length) { |
| 57 | return 'failure' |
| 58 | } |
| 59 | |
| 60 | // 8. Advance position by 1. |
| 61 | position.position++ |
| 62 | |
| 63 | // 9. Let encodedBody be the remainder of input. |
| 64 | const encodedBody = input.slice(mimeTypeLength + 1) |
| 65 | |
| 66 | // 10. Let body be the percent-decoding of encodedBody. |
| 67 | let body = stringPercentDecode(encodedBody) |
| 68 | |
| 69 | // 11. If mimeType ends with U+003B (;), followed by |
| 70 | // zero or more U+0020 SPACE, followed by an ASCII |
| 71 | // case-insensitive match for "base64", then: |
| 72 | if (/;(?:\u0020*)base64$/ui.test(mimeType)) { |
| 73 | // 1. Let stringBody be the isomorphic decode of body. |
| 74 | const stringBody = isomorphicDecode(body) |
| 75 | |
| 76 | // 2. Set body to the forgiving-base64 decode of |
| 77 | // stringBody. |
| 78 | body = forgivingBase64(stringBody) |
no test coverage detected