mirror of
https://github.com/nodejs/node.git
synced 2024-11-21 10:59:27 +00:00
6c85d40593
Fixes: https://github.com/nodejs/node/issues/53775 PR-URL: https://github.com/nodejs/node/pull/54748 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
'use strict';
|
|
// Flags: --expose-internals
|
|
|
|
require('../common');
|
|
const fixtures = require('../common/fixtures');
|
|
const assert = require('node:assert');
|
|
const { test } = require('node:test');
|
|
const { dataURLProcessor } = require('internal/data_url');
|
|
|
|
// https://github.com/web-platform-tests/wpt/blob/7c79d998ff42e52de90290cb847d1b515b3b58f7/fetch/data-urls/processing.any.js
|
|
test('parsing data URLs', async () => {
|
|
const tests = require(fixtures.path('wpt/fetch/data-urls/resources/data-urls.json'));
|
|
|
|
for (let i = 0; i < tests.length; i++) {
|
|
const input = tests[i][0];
|
|
const expectedMimeType = tests[i][1];
|
|
const expectedBody = expectedMimeType !== null ? new Uint8Array(tests[i][2]) : null;
|
|
|
|
if (!URL.canParse(input)) {
|
|
assert.strictEqual(expectedMimeType, null);
|
|
} else if (expectedMimeType === null) {
|
|
assert.strictEqual(dataURLProcessor(URL.parse(input)), 'failure');
|
|
} else {
|
|
const { mimeType, body } = dataURLProcessor(new URL(input));
|
|
|
|
assert.deepStrictEqual(expectedBody, body);
|
|
assert.deepStrictEqual(expectedMimeType, mimeType.toString());
|
|
}
|
|
}
|
|
});
|