Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
function scanForImportRules(elementImpl, cssRules, baseURL) {
if (!cssRules) {
return;
}
for (let i = 0; i < cssRules.length; ++i) {
if (cssRules[i].cssRules) {
// @media rule: keep searching inside it.
scanForImportRules(elementImpl, cssRules[i].cssRules, baseURL);
} else if (cssRules[i].href) {
// @import rule: fetch the resource and evaluate it.
// See http://dev.w3.org/csswg/cssom/#css-import-rule
// If loading of the style sheet fails its cssRules list is simply
// empty. I.e. an @import rule always has an associated style sheet.
const parsed = whatwgURL.parseURL(cssRules[i].href, { baseURL });
if (parsed === null) {
const window = elementImpl._ownerDocument._defaultView;
if (window) {
const error = new Error(`Could not parse CSS @import URL ${cssRules[i].href} relative to base URL ` +
`"${whatwgURL.serializeURL(baseURL)}"`);
error.type = "css @import URL parsing";
window._virtualConsole.emit("jsdomError", error);
}
} else {
fetchStylesheetInternal(elementImpl, whatwgURL.serializeURL(parsed), parsed);
}
}
}
}
} else if (cssRules[i].href) {
// @import rule: fetch the resource and evaluate it.
// See http://dev.w3.org/csswg/cssom/#css-import-rule
// If loading of the style sheet fails its cssRules list is simply
// empty. I.e. an @import rule always has an associated style sheet.
const parsed = whatwgURL.parseURL(cssRules[i].href, { baseURL });
if (parsed === null) {
const window = elementImpl._ownerDocument._defaultView;
if (window) {
const error = new Error(`Could not parse CSS @import URL ${cssRules[i].href} relative to base URL ` +
`"${whatwgURL.serializeURL(baseURL)}"`);
error.type = "css @import URL parsing";
window._virtualConsole.emit("jsdomError", error);
}
} else {
fetchStylesheetInternal(elementImpl, whatwgURL.serializeURL(parsed), parsed);
}
}
}
}
function isRelativeUrl(value) {
// A dummy protocol that shouldn't exist.
const protocol = 'asdoiasjdpoaisjd:';
let url;
try {
url = new URL(value, `${protocol}//foo`);
} catch (e) {
// URL is invalid.
return false;
}
// If the URL is relative, then the protocol will stay the same, but host
// could change due to protocol relative. Also check that the URL isn't
// absolute, since then it is using the dummy protocol we defined.
return url.protocol === protocol && !isAbsoluteUrl(value);
}
function normalizeFromURLOptions(options) {
// Checks on options that are invalid for `fromURL`
if (options.url !== undefined) {
throw new TypeError("Cannot supply a url option when using fromURL");
}
if (options.contentType !== undefined) {
throw new TypeError("Cannot supply a contentType option when using fromURL");
}
// Normalization of options which must be done before the rest of the fromURL code can use them, because they are
// given to request()
const normalized = Object.assign({}, options);
if (options.referrer !== undefined) {
normalized.referrer = (new URL(options.referrer)).href;
}
if (options.cookieJar === undefined) {
normalized.cookieJar = new CookieJar();
}
return normalized;
// All other options don't need to be processed yet, and can be taken care of in the normal course of things when
// `fromURL` calls `new JSDOM(html, options)`.
}
public updateOrAdd(input: IObjectToService): ServiceStore {
// TODO: Tighly coupled with OpenAPI at the moment... resolve this at a later time
const hostName = new url.URL(input.baseUrl).hostname || input.baseUrl;
const serviceName = input.name || hostName || input.baseUrl;
const baseSchema: OpenAPIObject =
serviceName !== undefined && this.cores[serviceName] !== undefined
? this.cores[serviceName].schema /* service exists by name */
: this.cores[hostName] !== undefined
? this.cores[hostName].schema /* service exists by base url */
: {
/* new service - some template schema */
openapi: "3.0.0",
info: {
title: "Internally built by unmock",
version: "0.0.0",
},
paths: {},
};
const newServiceCore = ServiceCore.from(baseSchema, {
if (options.url !== undefined) {
throw new TypeError("Cannot supply a url option when using fromURL");
}
if (options.contentType !== undefined) {
throw new TypeError("Cannot supply a contentType option when using fromURL");
}
// Normalization of options which must be done before the rest of the fromURL code can use them, because they are
// given to request()
const normalized = Object.assign({}, options);
if (options.userAgent === undefined) {
normalized.userAgent = DEFAULT_USER_AGENT;
}
if (options.referrer !== undefined) {
normalized.referrer = (new URL(options.referrer)).href;
}
if (options.cookieJar === undefined) {
normalized.cookieJar = new CookieJar();
}
return normalized;
// All other options don't need to be processed yet, and can be taken care of in the normal course of things when
// `fromURL` calls `new JSDOM(html, options)`.
}
static domainMatches (issuer, webId) {
let match
try {
webId = new URL(webId)
let webIdOrigin = webId.origin // drop the path
match = (issuer === webIdOrigin) || OidcManager.isSubdomain(webIdOrigin, issuer)
} catch (err) {
match = false
}
return match
}
if (options.url !== undefined) {
throw new TypeError("Cannot supply a url option when using fromURL");
}
if (options.contentType !== undefined) {
throw new TypeError("Cannot supply a contentType option when using fromURL");
}
// Normalization of options which must be done before the rest of the fromURL code can use them, because they are
// given to request()
const normalized = Object.assign({}, options);
if (options.userAgent === undefined) {
normalized.userAgent = DEFAULT_USER_AGENT;
}
if (options.referrer !== undefined) {
normalized.referrer = (new URL(options.referrer)).href;
}
if (options.cookieJar === undefined) {
normalized.cookieJar = new CookieJar();
}
return normalized;
// All other options don't need to be processed yet, and can be taken care of in the normal course of things when
// `fromURL` calls `new JSDOM(html, options)`.
}
function absResolve(importPath, sourceFileName, pluginOptions = {}) {
if (whatwgUrl.parseURL(importPath) !== null) {
return importPath;
}
const result = resolve.sync(importPath, {
basedir: basedirResolve(importPath, sourceFileName, pluginOptions),
extensions: pluginOptions.extensions || ['.mjs', '.js', 'json'],
moduleDirectory: pluginOptions.resolveDirectories || 'node_modules',
preserveSymlinks: false,
packageFilter(packageJson) {
packageJson.main = packageJson.module || packageJson['jsnext:main'] || packageJson.main;
return packageJson;
},
});
// use node's resolve to convert symlinks to real paths
return require.resolve(result);
exports.parseURLToResultingURLRecord = (url, document) => {
// https://html.spec.whatwg.org/#resolve-a-url
// Encoding stuff ignored; always UTF-8 for us, for now.
const baseURL = exports.documentBaseURL(document);
return whatwgURL.parseURL(url, { baseURL });
// This returns the resulting URL record; to get the resulting URL string, just serialize it.
};