mirror of
https://github.com/outline/outline.git
synced 2026-11-21 21:44:30 +03:00
* Upgrade @typescript-eslint dependencies from v6.21.0 to v8.33.0 - Updated @typescript-eslint/eslint-plugin from ^6.21.0 to ^8.33.0 - Updated @typescript-eslint/parser from ^6.21.0 to ^8.33.0 - Tested linting functionality to ensure compatibility - This brings the latest TypeScript ESLint features and bug fixes * lint * tsc --------- Co-authored-by: codegen-sh[bot] <131295404+codegen-sh[bot]@users.noreply.github.com> Co-authored-by: Tom Moor <tom@getoutline.com>
59 lines
1.2 KiB
TypeScript
59 lines
1.2 KiB
TypeScript
export function isHash(href: string) {
|
|
if (href[0] === "#") {
|
|
return true;
|
|
}
|
|
|
|
try {
|
|
const outline = new URL(window.location.href);
|
|
const parsed = new URL(href);
|
|
|
|
if (
|
|
outline.hostname === parsed.hostname &&
|
|
outline.pathname === parsed.pathname &&
|
|
!!parsed.hash
|
|
) {
|
|
return true;
|
|
}
|
|
} catch (_err) {
|
|
// failed to parse as url
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Decodes a URI component without throwing an error in case of invalid encoding.
|
|
*
|
|
* @param text The text to decode.
|
|
* @returns The decoded text.
|
|
*/
|
|
export function decodeURIComponentSafe(text: string) {
|
|
try {
|
|
return text
|
|
? decodeURIComponent(text.replace(/%(?![0-9][0-9a-fA-F]+)/g, "%25"))
|
|
: text;
|
|
} catch (_) {
|
|
return text;
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Redirects to a new page
|
|
*
|
|
* @param url
|
|
*/
|
|
export function redirectTo(url: string) {
|
|
window.location.href = url;
|
|
}
|
|
|
|
/**
|
|
* Check if the path is a valid path for redirect after login.
|
|
*
|
|
* @param input A path potentially including query string
|
|
* @returns boolean indicating if the path is a valid redirect
|
|
*/
|
|
export const isAllowedLoginRedirect = (input: string) => {
|
|
const path = input.split("?")[0];
|
|
return !["/", "/create", "/home", "/logout", "/auth/"].includes(path);
|
|
};
|