mirror of
https://github.com/Redocly/redoc.git
synced 2024-11-22 16:46:34 +03:00
fix: crash in node due to broken URL parsing
This commit is contained in:
parent
3f6765078e
commit
8df2b97a66
|
@ -147,7 +147,7 @@ export function resolveUrl(url: string, to: string) {
|
||||||
let res;
|
let res;
|
||||||
if (to.startsWith('//')) {
|
if (to.startsWith('//')) {
|
||||||
const { protocol: specProtocol } = parse(url);
|
const { protocol: specProtocol } = parse(url);
|
||||||
res = `${specProtocol}${to}`;
|
res = `${specProtocol || 'https:'}${to}`;
|
||||||
} else if (isAbsoluteUrl(to)) {
|
} else if (isAbsoluteUrl(to)) {
|
||||||
res = to;
|
res = to;
|
||||||
} else if (!to.startsWith('/')) {
|
} else if (!to.startsWith('/')) {
|
||||||
|
@ -163,7 +163,7 @@ export function resolveUrl(url: string, to: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function getBasePath(serverUrl: string): string {
|
export function getBasePath(serverUrl: string): string {
|
||||||
return new URL(serverUrl).pathname;
|
return parseURL(serverUrl).pathname;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function titleize(text: string) {
|
export function titleize(text: string) {
|
||||||
|
@ -171,7 +171,16 @@ export function titleize(text: string) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function removeQueryString(serverUrl: string): string {
|
export function removeQueryString(serverUrl: string): string {
|
||||||
const url = new URL(serverUrl);
|
const url = parseURL(serverUrl);
|
||||||
url.search = '';
|
url.search = '';
|
||||||
return url.toString();
|
return url.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function parseURL(url: string) {
|
||||||
|
if (typeof URL === undefined) {
|
||||||
|
// node
|
||||||
|
return new (require('url')).URL(url);
|
||||||
|
} else {
|
||||||
|
return new URL(url);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user