url.test.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. import { normalizeLink } from "../src/url";
  2. describe("normalizeLink", () => {
  3. // NOTE not an extensive XSS test suite, just to check if we're not
  4. // regressing in sanitization
  5. it("should sanitize links", () => {
  6. expect(
  7. // eslint-disable-next-line no-script-url
  8. normalizeLink(`javascript://%0aalert(document.domain)`).startsWith(
  9. // eslint-disable-next-line no-script-url
  10. `javascript:`,
  11. ),
  12. ).toBe(false);
  13. expect(normalizeLink("ola")).toBe("ola");
  14. expect(normalizeLink(" ola")).toBe("ola");
  15. expect(normalizeLink("https://www.excalidraw.com")).toBe(
  16. "https://www.excalidraw.com",
  17. );
  18. expect(normalizeLink("www.excalidraw.com")).toBe("www.excalidraw.com");
  19. expect(normalizeLink("/ola")).toBe("/ola");
  20. expect(normalizeLink("http://test")).toBe("http://test");
  21. expect(normalizeLink("ftp://test")).toBe("ftp://test");
  22. expect(normalizeLink("file://")).toBe("file://");
  23. expect(normalizeLink("file://")).toBe("file://");
  24. expect(normalizeLink("[test](https://test)")).toBe("[test](https://test)");
  25. expect(normalizeLink("[[test]]")).toBe("[[test]]");
  26. expect(normalizeLink("<test>")).toBe("<test>");
  27. expect(normalizeLink("test&")).toBe("test&");
  28. });
  29. });