mirror of https://github.com/webpack/webpack.git
check for Windows absolute url in URLAbsoluteSpecifier util
This commit is contained in:
parent
f4abe4a550
commit
d42d2b51df
|
@ -29,7 +29,7 @@ const RuntimeGlobals = require("./RuntimeGlobals");
|
|||
const UnsupportedSchemeError = require("./UnsupportedSchemeError");
|
||||
const WebpackError = require("./WebpackError");
|
||||
const { decodeDataURI } = require("./util/DataURI");
|
||||
const { getScheme, isSchemeSupported } = require("./util/URLAbsoluteSpecifier");
|
||||
const { getScheme } = require("./util/URLAbsoluteSpecifier");
|
||||
const {
|
||||
compareLocations,
|
||||
concatComparators,
|
||||
|
@ -137,7 +137,7 @@ const asBuffer = input => {
|
|||
const readResourceFn = fs => {
|
||||
return (resource, callback) => {
|
||||
const scheme = getScheme(resource);
|
||||
if (scheme && isSchemeSupported(scheme)) {
|
||||
if (scheme) {
|
||||
switch (scheme) {
|
||||
case "data":
|
||||
return process.nextTick(() => {
|
||||
|
|
|
@ -22,11 +22,7 @@ const BasicMatcherRulePlugin = require("./rules/BasicMatcherRulePlugin");
|
|||
const RuleSetCompiler = require("./rules/RuleSetCompiler");
|
||||
const UseEffectRulePlugin = require("./rules/UseEffectRulePlugin");
|
||||
const LazySet = require("./util/LazySet");
|
||||
const {
|
||||
getScheme,
|
||||
getMimetype,
|
||||
isSchemeSupported
|
||||
} = require("./util/URLAbsoluteSpecifier");
|
||||
const { getScheme, getMimetype } = require("./util/URLAbsoluteSpecifier");
|
||||
const { cachedCleverMerge, cachedSetProperty } = require("./util/cleverMerge");
|
||||
const { join } = require("./util/fs");
|
||||
|
||||
|
@ -327,7 +323,6 @@ class NormalModuleFactory extends ModuleFactory {
|
|||
let resource;
|
||||
/** @type {string | undefined} */
|
||||
const scheme = getScheme(unresolvedResource);
|
||||
const supportedScheme = scheme ? isSchemeSupported(scheme) : false;
|
||||
let resourceResolveData;
|
||||
let loaders;
|
||||
|
||||
|
@ -391,7 +386,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|||
? resource.replace(/\?.*/, "")
|
||||
: resourcePath,
|
||||
resourceQuery,
|
||||
mimetype: supportedScheme ? getMimetype(scheme, resource) : "",
|
||||
mimetype: scheme ? getMimetype(scheme, resource) : "",
|
||||
issuer: contextInfo.issuer,
|
||||
compiler: contextInfo.compiler
|
||||
});
|
||||
|
@ -515,7 +510,7 @@ class NormalModuleFactory extends ModuleFactory {
|
|||
return continueCallback();
|
||||
}
|
||||
|
||||
if (supportedScheme) {
|
||||
if (scheme) {
|
||||
resource = unresolvedResource;
|
||||
continueCallback();
|
||||
} else {
|
||||
|
|
|
@ -10,7 +10,7 @@ const { getMimetype: getDataUrlMimetype } = require("./DataURI");
|
|||
/** @typedef {import("./fs").InputFileSystem} InputFileSystem */
|
||||
/** @typedef {(error: Error|null, result?: Buffer) => void} ErrorFirstCallback */
|
||||
|
||||
const supportedSchemes = new Set(["data", "file", "http", "https"]);
|
||||
const backSlashCharCode = "\\".charCodeAt(0);
|
||||
const aLowerCaseCharCode = "a".charCodeAt(0);
|
||||
const zLowerCaseCharCode = "z".charCodeAt(0);
|
||||
const aUpperCaseCharCode = "A".charCodeAt(0);
|
||||
|
@ -53,6 +53,8 @@ function getScheme(specifier) {
|
|||
|
||||
// Scheme must end with colon
|
||||
if (ch !== colonCharCode) return undefined;
|
||||
// Check for Windows absolute path
|
||||
if (specifier.charCodeAt(i + 1) === backSlashCharCode) return undefined;
|
||||
|
||||
return specifier.slice(0, i).toLowerCase();
|
||||
}
|
||||
|
@ -79,15 +81,6 @@ function getMimetype(scheme, specifier) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param {string} scheme scheme
|
||||
* @returns {boolean} supported or not
|
||||
*/
|
||||
function isSchemeSupported(scheme) {
|
||||
return supportedSchemes.has(scheme);
|
||||
}
|
||||
|
||||
exports.getScheme = getScheme;
|
||||
exports.getMimetype = getMimetype;
|
||||
exports.getProtocol = getProtocol;
|
||||
exports.isSchemeSupported = isSchemeSupported;
|
||||
|
|
Loading…
Reference in New Issue