diff --git a/shared/editor/embeds/index.tsx b/shared/editor/embeds/index.tsx index cbf2226d9..cf4ab4279 100644 --- a/shared/editor/embeds/index.tsx +++ b/shared/editor/embeds/index.tsx @@ -93,7 +93,9 @@ export class EmbedDescriptor { matcher(url: string): false | RegExpMatchArray { const regexes = this.regexMatch ?? []; - const settingsDomainRegex = urlRegex(this.settings?.url); + const settingsDomainRegex = this.settings?.url + ? urlRegex(this.settings?.url) + : undefined; if (settingsDomainRegex) { regexes.unshift(settingsDomainRegex); @@ -372,11 +374,13 @@ const embeds: EmbedDescriptor[] = [ keywords: "spreadsheet", regexMatch: [new RegExp("^https?://([a-z.-]+\\.)?getgrist\\.com/(.+)$")], transformMatch: (matches: RegExpMatchArray) => { - if (matches[0].includes("style=singlePage")) { - return matches[0]; + const input = matches.input ?? matches[0]; + + if (input.includes("style=singlePage")) { + return input; } - return matches[0].replace(/(\?embed=true)?$/, "?embed=true"); + return input.replace(/(\?embed=true)?$/, "?embed=true"); }, icon: Grist, }), diff --git a/shared/utils/urls.test.ts b/shared/utils/urls.test.ts index 227881b8b..d5eef39fa 100644 --- a/shared/utils/urls.test.ts +++ b/shared/utils/urls.test.ts @@ -138,5 +138,12 @@ describe("#urlRegex", () => { it("should return corresponding regex otherwise", () => { const regex = urlRegex("https://docs.google.com"); expect(regex?.source).toBe(/https:\/\/docs\.google\.com/.source); + expect(regex?.test("https://docs.google.com")).toBe(true); + expect(regex?.test("https://docs.google.com/")).toBe(true); + expect(regex?.test("https://docs.google.com/d/123")).toBe(true); + expect(regex?.test("http://google.com")).toBe(false); + expect(regex?.test("http://docs.google.com")).toBe(false); + expect(regex?.test("http://docs.google.com/")).toBe(false); + expect(regex?.test("http://docs.google.com/d/123")).toBe(false); }); });