mirror of
https://github.com/outline/outline.git
synced 2026-11-30 17:10:36 +03:00
chore: Remove unnecessary URL parsing (#14454)
This commit is contained in:
1 parent
133fba4dd0
commit
f0401f83e7
8 files changed
+21
-35
No files matched your search
@@ -35,7 +35,7 @@ interface Props {
|
||||
export function TeamSwitcher({ sessions, description }: Props) {
|
||||
const { t } = useTranslation();
|
||||
const [showLogin, setShowLogin] = useState(false);
|
||||
const url = new URL(window.location.href);
|
||||
const { pathname, search } = window.location;
|
||||
|
||||
if (showLogin) {
|
||||
return <Login onBack={() => setShowLogin(false)} />;
|
||||
@@ -57,7 +57,7 @@ export function TeamSwitcher({ sessions, description }: Props) {
|
||||
</Text>
|
||||
{Object.keys(sessions).map((teamId) => {
|
||||
const session = sessions[teamId];
|
||||
const location = sanitizeUrl(session.url + url.pathname + url.search);
|
||||
const location = sanitizeUrl(session.url + pathname + search);
|
||||
return (
|
||||
<TeamLink href={location} key={teamId}>
|
||||
<Avatar
|
||||
|
||||
@@ -279,15 +279,14 @@ function splitViewPathFromClick(event: MouseEvent): string | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const url = new URL(anchor.href, window.location.origin);
|
||||
if (
|
||||
url.origin !== window.location.origin ||
|
||||
!isSplittablePath(url.pathname)
|
||||
anchor.origin !== window.location.origin ||
|
||||
!isSplittablePath(anchor.pathname)
|
||||
) {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
return `${url.pathname}${url.search}${url.hash}`;
|
||||
return `${anchor.pathname}${anchor.search}${anchor.hash}`;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+2
-3
@@ -54,12 +54,11 @@ export function isHash(href: string) {
|
||||
}
|
||||
|
||||
try {
|
||||
const outline = new URL(window.location.href);
|
||||
const parsed = new URL(href);
|
||||
|
||||
if (
|
||||
outline.hostname === parsed.hostname &&
|
||||
outline.pathname === parsed.pathname &&
|
||||
window.location.hostname === parsed.hostname &&
|
||||
window.location.pathname === parsed.pathname &&
|
||||
!!parsed.hash
|
||||
) {
|
||||
return true;
|
||||
|
||||
@@ -24,12 +24,12 @@ import { parseState } from "@server/utils/passport";
|
||||
* @returns the host if trusted, otherwise falls back to the base domain from env.URL.
|
||||
*/
|
||||
async function getValidatedHost(host: string): Promise<string> {
|
||||
const fallback = new URL(env.URL).host;
|
||||
|
||||
if (!env.isCloudHosted) {
|
||||
return host;
|
||||
}
|
||||
|
||||
const fallback = new URL(env.URL).host;
|
||||
|
||||
if (!host) {
|
||||
return fallback;
|
||||
}
|
||||
|
||||
@@ -288,10 +288,9 @@ class Team extends ParanoidModel<
|
||||
}
|
||||
|
||||
get url() {
|
||||
const url = new URL(env.URL);
|
||||
|
||||
// custom domain
|
||||
if (this.domain) {
|
||||
const url = new URL(env.URL);
|
||||
return `${url.protocol}//${this.domain}${url.port ? `:${url.port}` : ""}`;
|
||||
}
|
||||
|
||||
@@ -299,6 +298,7 @@ class Team extends ParanoidModel<
|
||||
return env.URL;
|
||||
}
|
||||
|
||||
const url = new URL(env.URL);
|
||||
url.host = `${this.subdomain}.${getBaseDomain()}`;
|
||||
return url.href.replace(/\/$/, "");
|
||||
}
|
||||
|
||||
@@ -1291,9 +1291,7 @@ export class ProsemirrorHelper extends SharedProsemirrorHelper {
|
||||
const src = source.href;
|
||||
|
||||
// Skip invalid URLs
|
||||
try {
|
||||
new URL(src);
|
||||
} catch {
|
||||
if (!URL.canParse(src)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,9 +86,7 @@ export class TextHelper {
|
||||
await Promise.all(
|
||||
chunk.map(async (image) => {
|
||||
// Skip attempting to fetch images that are not valid urls
|
||||
try {
|
||||
new URL(image.src);
|
||||
} catch (_e) {
|
||||
if (!URL.canParse(image.src)) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+8
-16
@@ -103,23 +103,15 @@ export class ValidateURL {
|
||||
if (!isUrl(url)) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
const urlObj = new URL(url);
|
||||
if (urlObj.protocol !== "mention:") {
|
||||
return false;
|
||||
}
|
||||
|
||||
const { id, mentionType, modelId } = parseMentionUrl(url);
|
||||
return (
|
||||
(!id || isUUID(id)) &&
|
||||
!!mentionType &&
|
||||
Object.values(MentionType).includes(mentionType as MentionType) &&
|
||||
!!modelId &&
|
||||
isUUID(modelId)
|
||||
);
|
||||
} catch (_err) {
|
||||
return false;
|
||||
}
|
||||
const { id, mentionType, modelId } = parseMentionUrl(url);
|
||||
return (
|
||||
(!id || isUUID(id)) &&
|
||||
!!mentionType &&
|
||||
Object.values(MentionType).includes(mentionType as MentionType) &&
|
||||
!!modelId &&
|
||||
isUUID(modelId)
|
||||
);
|
||||
};
|
||||
|
||||
public static message = "Must be a valid url";
|
||||
|
||||
Reference in new issue
Block a user