fix: address CodeQL and code quality review comments
Replace polynomial trailing-slash regex with removeTrailingSlash helper and remove unused ModalFormFooter import in quick-add-app modal.
This commit is contained in:
5 files changed
+13
-6
No files matched your search
@@ -1,3 +1,5 @@
|
||||
import { removeTrailingSlash } from "@homarr/common";
|
||||
|
||||
import { integrationIconSlugs } from "./docker-integration-match";
|
||||
import type { IntegrationKind } from "./integration";
|
||||
import { getIntegrationDefaultPort } from "./integration";
|
||||
@@ -20,7 +22,7 @@ export const buildIntegrationUrl = (
|
||||
mode: UrlTemplateMode,
|
||||
dockerPort?: number,
|
||||
): string => {
|
||||
const host = baseHost.trim().replace(/\/+$/, "");
|
||||
const host = removeTrailingSlash(baseHost.trim());
|
||||
if (!host) return "";
|
||||
const port = dockerPort ?? getIntegrationDefaultPort(kind);
|
||||
return buildUrl(getSlugForKind(kind), host, mode, port ?? undefined);
|
||||
@@ -32,7 +34,7 @@ export const buildAppUrl = (
|
||||
mode: UrlTemplateMode,
|
||||
dockerPort?: number,
|
||||
): string => {
|
||||
const host = baseHost.trim().replace(/\/+$/, "");
|
||||
const host = removeTrailingSlash(baseHost.trim());
|
||||
if (!host) return "";
|
||||
const slug = containerName.toLowerCase().replace(/[^a-z0-9-]/g, "-");
|
||||
return buildUrl(slug, host, mode, dockerPort);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { objectKeys } from "@homarr/common";
|
||||
import { objectKeys, removeTrailingSlash } from "@homarr/common";
|
||||
import type { AtLeastOneOf } from "@homarr/common/types";
|
||||
|
||||
import { createDocumentationLink } from "./docs";
|
||||
@@ -475,7 +475,7 @@ export const getIntegrationDefaultPort = (kind: IntegrationKind): number | undef
|
||||
export const getIntegrationApiKeyUrl = (integrationUrl: string, kind: IntegrationKind): string | null => {
|
||||
const definition = integrationDefs[kind];
|
||||
if (!("apiKeySettingsPath" in definition)) return null;
|
||||
const base = integrationUrl.replace(/\/+$/, "");
|
||||
const base = removeTrailingSlash(integrationUrl);
|
||||
if (!base) return null;
|
||||
return `${base}${definition.apiKeySettingsPath}`;
|
||||
};
|
||||
|
||||
@@ -22,6 +22,7 @@ describe("buildIntegrationUrl", () => {
|
||||
|
||||
it("strips trailing slashes from host", () => {
|
||||
expect(buildIntegrationUrl("sonarr", "homelab.local/", "subdomain")).toBe("https://sonarr.homelab.local");
|
||||
expect(buildIntegrationUrl("sonarr", "homelab.local///", "subdomain")).toBe("https://sonarr.homelab.local");
|
||||
});
|
||||
|
||||
it("returns empty string for empty host", () => {
|
||||
|
||||
Reference in new issue
Block a user