Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)`.
}
async normalize(source: string): Promise {
const url = new URL(source);
if (!this.matchesHost(url)) {
return source;
}
const match = url.hash.match(EDITOR_HASH_PATTERN);
if (!match) {
return source;
}
let path = `/api/v1/gist/${match[1]}`;
if (match[2]) {
path += `/${match[2]}`;
}
const mimeType = new MIMEType(options.contentType);
if (!mimeType.isHTML() && !mimeType.isXML()) {
throw new RangeError(`The given content type of "${options.contentType}" was not a HTML or XML content type`);
}
transformed.windowOptions.contentType = mimeType.essence;
transformed.windowOptions.parsingMode = mimeType.isHTML() ? "html" : "xml";
}
if (options.url !== undefined) {
transformed.windowOptions.url = (new URL(options.url)).href;
}
if (options.referrer !== undefined) {
transformed.windowOptions.referrer = (new URL(options.referrer)).href;
}
if (options.userAgent !== undefined) {
transformed.windowOptions.userAgent = String(options.userAgent);
}
if (options.includeNodeLocations) {
if (transformed.windowOptions.parsingMode === "xml") {
throw new TypeError("Cannot set includeNodeLocations to true with an XML content type");
}
transformed.windowOptions.parseOptions = { locationInfo: true };
}
transformed.windowOptions.cookieJar = options.cookieJar === undefined ?
new CookieJar() :
createProfileDataFromUri (uri) {
let param
let url = new URL(uri)
let baseProfile = this.getBaseProfile()
let newProfile = {}
param = url.searchParams.get('command')
if (param) newProfile.command = param
if (!('command' in newProfile)) newProfile.command = baseProfile.command
param = url.searchParams.get('args')
if (param) newProfile.args = JSON.parse(param)
if (!('args' in newProfile && newProfile.args)) newProfile.args = baseProfile.args
param = url.searchParams.get('name')
if (param) newProfile.name = param
if (!('name' in newProfile)) newProfile.name = baseProfile.name
param = url.searchParams.get('cwd')
if (param) newProfile.cwd = param
if (!('cwd' in newProfile)) newProfile.cwd = baseProfile.cwd
param = url.searchParams.get('env')
if (param) newProfile.env = JSON.parse(param)