| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -6,12 +6,14 @@ require('internal/modules/cjs/loader'); | |||
| 6 | 6 | const { | |
| 7 | 7 | FunctionPrototypeBind, | |
| 8 | 8 | ObjectSetPrototypeOf, | |
| 9 | + RegExpPrototypeExec, | ||
| 9 | 10 | SafeWeakMap, | |
| 10 | 11 | StringPrototypeStartsWith, | |
| 11 | 12 | } = primordials; | |
| 12 | 13 | ||
| 13 | 14 | const { | |
| 14 | 15 | ERR_INVALID_ARG_VALUE, | |
| 16 | + ERR_INVALID_MODULE_SPECIFIER, | ||
| 15 | 17 | ERR_INVALID_RETURN_PROPERTY, | |
| 16 | 18 | ERR_INVALID_RETURN_PROPERTY_VALUE, | |
| 17 | 19 | ERR_INVALID_RETURN_VALUE, | |
@@ -107,6 +109,15 @@ class Loader { | |||
| 107 | 109 | } | |
| 108 | 110 | ||
| 109 | 111 | const { format } = getFormatResponse; | |
| 112 | + if (format === null) { | ||
| 113 | + const dataUrl = RegExpPrototypeExec( | ||
| 114 | + /^data:([^/]+\/[^;,]+)(?:[^,]*?)(;base64)?,/, | ||
| 115 | + url, | ||
| 116 | + ); | ||
| 117 | + throw new ERR_INVALID_MODULE_SPECIFIER( | ||
| 118 | + url, | ||
| 119 | + dataUrl ? `has an unsupported MIME type "${dataUrl[1]}"` : ''); | ||
| 120 | + } | ||
| 110 | 121 | if (typeof format !== 'string') { | |
| 111 | 122 | throw new ERR_INVALID_RETURN_PROPERTY_VALUE( | |
| 112 | 123 | 'string', 'loader getFormat', 'format', format); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -99,7 +99,7 @@ function createBase64URL(mime, body) { | |||
| 99 | 99 | await import(plainESMURL); | |
| 100 | 100 | common.mustNotCall()(); | |
| 101 | 101 | } catch (e) { | |
| 102 | - assert.strictEqual(e.code, 'ERR_INVALID_RETURN_PROPERTY_VALUE'); | ||
| 102 | + assert.strictEqual(e.code, 'ERR_INVALID_MODULE_SPECIFIER'); | ||
| 103 | 103 | } | |
| 104 | 104 | } | |
| 105 | 105 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,24 @@ | |||
| 1 | + 'use strict'; | ||
| 2 | + const common = require('../common'); | ||
| 3 | + const assert = require('assert'); | ||
| 4 | + | ||
| 5 | + (async () => { | ||
| 6 | + await assert.rejects(import('data:text/plain,export default0'), { | ||
| 7 | + code: 'ERR_INVALID_MODULE_SPECIFIER', | ||
| 8 | + message: | ||
| 9 | + 'Invalid module "data:text/plain,export default0" has an unsupported ' + | ||
| 10 | + 'MIME type "text/plain"', | ||
| 11 | + }); | ||
| 12 | + await assert.rejects(import('data:text/plain;base64,'), { | ||
| 13 | + code: 'ERR_INVALID_MODULE_SPECIFIER', | ||
| 14 | + message: | ||
| 15 | + 'Invalid module "data:text/plain;base64," has an unsupported ' + | ||
| 16 | + 'MIME type "text/plain"', | ||
| 17 | + }); | ||
| 18 | + await assert.rejects(import('data:application/json,[]'), { | ||
| 19 | + code: 'ERR_INVALID_MODULE_SPECIFIER', | ||
| 20 | + message: | ||
| 21 | + 'Invalid module "data:application/json,[]" has an unsupported ' + | ||
| 22 | + 'MIME type "application/json"', | ||
| 23 | + }); | ||
| 24 | + })().then(common.mustCall()); | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments