Unverified Commit 118b30d5 authored by Marius van den Beek's avatar Marius van den Beek Committed by GitHub
Browse files

Merge pull request #20300 from davelopez/25.0_fix_multi_url_proxy

[25.0] Skip multiple pasted URLs when checking for remote Zip
parents 900ad2fb 305f6b8b
Loading
Loading
Loading
Loading
+29 −0
Original line number Diff line number Diff line
import { isValidUrl } from "./zipExplorer";

describe("useZipExplorer", () => {
    describe("isValidUrl", () => {
        it("should return true for valid URLs", () => {
            expect(isValidUrl("http://example.com")).toBe(true);
            expect(isValidUrl("https://example.com")).toBe(true);
        });

        it("should return false for invalid URLs", () => {
            expect(isValidUrl("invalid-url")).toBe(false);
            expect(isValidUrl("htp://example.com")).toBe(false);
        });

        it("should return false for empty strings", () => {
            expect(isValidUrl("")).toBe(false);
        });

        it("should return false for null or undefined values", () => {
            expect(isValidUrl(null)).toBe(false);
            expect(isValidUrl(undefined)).toBe(false);
        });

        it("should return false for multiple URLs", () => {
            expect(isValidUrl("http://example.com\nhttp://example2.com")).toBe(false);
            expect(isValidUrl("https://example.com https://example2.com")).toBe(false);
        });
    });
});
+6 −1
Original line number Diff line number Diff line
@@ -340,7 +340,7 @@ export async function isRemoteZipFile(url: string): Promise<boolean> {
}

export function isValidUrl(inputUrl?: string | null): boolean {
    if (!inputUrl) {
    if (!inputUrl || isMultiLine(inputUrl)) {
        return false;
    }
    try {
@@ -351,6 +351,11 @@ export function isValidUrl(inputUrl?: string | null): boolean {
    }
}

function isMultiLine(inputString: string): boolean {
    const hasLineBreaks = inputString.includes("\n") || inputString.includes("\\n");
    return hasLineBreaks;
}

export function isRoCrateZip(explorer?: IZipExplorer): explorer is ROCrateZipExplorer {
    return explorer !== undefined && hasRoCrateMetadata(explorer);
}