silverwolf-x/project / packages /next /src /client /lib /javascript-url.ts
silverwolf-x's picture
download
raw
976 Bytes
// Adapted from React's sanitizeURL function found here: https://github.com/facebook/react/blob/b565373afd0cc1988497e1107106e851e8cfb261/packages/react-dom-bindings/src/shared/sanitizeURL.js
// A javascript: URL can contain leading C0 control or \u0020 SPACE,
// and any newline or tab are filtered out as if they're not part of the URL.
// https://url.spec.whatwg.org/#url-parsing
// Tab or newline are defined as \r\n\t:
// https://infra.spec.whatwg.org/#ascii-tab-or-newline
// A C0 control is a code point in the range \u0000 NULL to \u001F
// INFORMATION SEPARATOR ONE, inclusive:
// https://infra.spec.whatwg.org/#c0-control-or-space
const isJavaScriptProtocol =
// eslint-disable-next-line no-control-regex
/^[\u0000-\u001F ]*j[\r\n\t]*a[\r\n\t]*v[\r\n\t]*a[\r\n\t]*s[\r\n\t]*c[\r\n\t]*r[\r\n\t]*i[\r\n\t]*p[\r\n\t]*t[\r\n\t]*:/i
export function isJavaScriptURLString(url: string): boolean {
return isJavaScriptProtocol.test('' + (url as unknown as string))
}

Xet Storage Details

Size:
976 Bytes
·
Xet hash:
ac580e75bc6d5c94cc2ecfae2f321bd7db290c84654c1c1fa3a5e9dbae2163e8

Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.