mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 08:37:25 +02:00
add isValidPathname
This commit is contained in:
parent
4e8b361d00
commit
da8ccd0419
2 changed files with 29 additions and 0 deletions
|
@ -12,6 +12,7 @@ import camelCase from 'lodash.camelcase';
|
|||
import kebabCase from 'lodash.kebabcase';
|
||||
import escapeStringRegexp from 'escape-string-regexp';
|
||||
import fs from 'fs-extra';
|
||||
import {URL} from 'url';
|
||||
|
||||
const fileHash = new Map();
|
||||
export async function generate(
|
||||
|
@ -327,3 +328,14 @@ export function getEditUrl(fileRelativePath: string, editUrl?: string) {
|
|||
? normalizeUrl([editUrl, posixPath(fileRelativePath)])
|
||||
: undefined;
|
||||
}
|
||||
|
||||
export function isValidPathname(str: string): boolean {
|
||||
if (!str.startsWith('/')) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
return new URL(str, 'https://domain.com').pathname === str;
|
||||
} catch (e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue