From 98a182c892050c6183a3e7260b204623409080a6 Mon Sep 17 00:00:00 2001 From: Tom Moor Date: Sat, 8 Jul 2023 12:04:03 -0400 Subject: [PATCH] Improve reliability of embed regex (missing start char) --- shared/editor/embeds/Abstract.tsx | 4 ++-- shared/editor/embeds/Airtable.tsx | 2 +- shared/editor/embeds/Cawemo.tsx | 2 +- shared/editor/embeds/DBDiagram.tsx | 2 +- shared/editor/embeds/Descript.tsx | 4 +++- shared/editor/embeds/Figma.tsx | 2 +- shared/editor/embeds/JSFiddle.tsx | 2 +- shared/editor/embeds/Otter.tsx | 2 +- shared/editor/embeds/Spotify.tsx | 2 +- shared/editor/embeds/Tldraw.tsx | 2 +- 10 files changed, 13 insertions(+), 11 deletions(-) diff --git a/shared/editor/embeds/Abstract.tsx b/shared/editor/embeds/Abstract.tsx index 89dd37b0f..f0437d8b7 100644 --- a/shared/editor/embeds/Abstract.tsx +++ b/shared/editor/embeds/Abstract.tsx @@ -15,8 +15,8 @@ function Abstract(props: Props) { } Abstract.ENABLED = [ - new RegExp("https?://share\\.(?:go)?abstract\\.com/(.*)$"), - new RegExp("https?://app\\.(?:go)?abstract\\.com/(?:share|embed)/(.*)$"), + new RegExp("^https?://share\\.(?:go)?abstract\\.com/(.*)$"), + new RegExp("^https?://app\\.(?:go)?abstract\\.com/(?:share|embed)/(.*)$"), ]; export default Abstract; diff --git a/shared/editor/embeds/Airtable.tsx b/shared/editor/embeds/Airtable.tsx index 887c4f03b..856025b1c 100644 --- a/shared/editor/embeds/Airtable.tsx +++ b/shared/editor/embeds/Airtable.tsx @@ -2,7 +2,7 @@ import * as React from "react"; import Frame from "../components/Frame"; import { EmbedProps as Props } from "."; -const URL_REGEX = new RegExp("https://airtable.com/(?:embed/)?(shr.*)$"); +const URL_REGEX = new RegExp("^https://airtable.com/(?:embed/)?(shr.*)$"); function Airtable(props: Props) { const { matches } = props.attrs; diff --git a/shared/editor/embeds/Cawemo.tsx b/shared/editor/embeds/Cawemo.tsx index f04b9445f..f033d0eba 100644 --- a/shared/editor/embeds/Cawemo.tsx +++ b/shared/editor/embeds/Cawemo.tsx @@ -2,7 +2,7 @@ import * as React from "react"; import Frame from "../components/Frame"; import { EmbedProps as Props } from "."; -const URL_REGEX = new RegExp("https?://cawemo.com/(?:share|embed)/(.*)$"); +const URL_REGEX = new RegExp("^https?://cawemo.com/(?:share|embed)/(.*)$"); export default function Cawemo(props: Props) { const { matches } = props.attrs; diff --git a/shared/editor/embeds/DBDiagram.tsx b/shared/editor/embeds/DBDiagram.tsx index 826e61081..d5aa4cc77 100644 --- a/shared/editor/embeds/DBDiagram.tsx +++ b/shared/editor/embeds/DBDiagram.tsx @@ -17,4 +17,4 @@ export default function DBDiagram(props: Props) { ); } -DBDiagram.ENABLED = [new RegExp("https://dbdiagram.io/(embed|d)/(\\w+)$")]; +DBDiagram.ENABLED = [new RegExp("^https://dbdiagram.io/(embed|d)/(\\w+)$")]; diff --git a/shared/editor/embeds/Descript.tsx b/shared/editor/embeds/Descript.tsx index 8fb896b53..2d25453c2 100644 --- a/shared/editor/embeds/Descript.tsx +++ b/shared/editor/embeds/Descript.tsx @@ -15,4 +15,6 @@ export default function Descript(props: Props) { ); } -Descript.ENABLED = [new RegExp("https?://share\\.descript\\.com/view/(\\w+)$")]; +Descript.ENABLED = [ + new RegExp("^https?://share\\.descript\\.com/view/(\\w+)$"), +]; diff --git a/shared/editor/embeds/Figma.tsx b/shared/editor/embeds/Figma.tsx index 5f413037b..4c699da42 100644 --- a/shared/editor/embeds/Figma.tsx +++ b/shared/editor/embeds/Figma.tsx @@ -15,7 +15,7 @@ function Figma(props: Props) { Figma.ENABLED = [ new RegExp( - "https://([w.-]+\\.)?figma\\.com/(file|proto)/([0-9a-zA-Z]{22,128})(?:/.*)?$" + "^https://([w.-]+\\.)?figma\\.com/(file|proto)/([0-9a-zA-Z]{22,128})(?:/.*)?$" ), ]; diff --git a/shared/editor/embeds/JSFiddle.tsx b/shared/editor/embeds/JSFiddle.tsx index fcc2067ad..8e9a43863 100644 --- a/shared/editor/embeds/JSFiddle.tsx +++ b/shared/editor/embeds/JSFiddle.tsx @@ -20,6 +20,6 @@ function JSFiddle(props: Props) { ); } -JSFiddle.ENABLED = [new RegExp("https?://jsfiddle\\.net/(.*)/(.*)$")]; +JSFiddle.ENABLED = [new RegExp("^https?://jsfiddle\\.net/(.*)/(.*)$")]; export default JSFiddle; diff --git a/shared/editor/embeds/Otter.tsx b/shared/editor/embeds/Otter.tsx index 5909ebb59..d0264c7fe 100644 --- a/shared/editor/embeds/Otter.tsx +++ b/shared/editor/embeds/Otter.tsx @@ -14,6 +14,6 @@ function Otter(props: Props) { ); } -Otter.ENABLED = [new RegExp("https?://otter\\.ai/[su]/(.*)$")]; +Otter.ENABLED = [new RegExp("^https?://otter\\.ai/[su]/(.*)$")]; export default Otter; diff --git a/shared/editor/embeds/Spotify.tsx b/shared/editor/embeds/Spotify.tsx index 25ace7092..3fe315687 100644 --- a/shared/editor/embeds/Spotify.tsx +++ b/shared/editor/embeds/Spotify.tsx @@ -39,6 +39,6 @@ const SpotifyFrame = styled(Frame)` border-radius: 13px; `; -Spotify.ENABLED = [new RegExp("https?://open\\.spotify\\.com/(.*)$")]; +Spotify.ENABLED = [new RegExp("^https?://open\\.spotify\\.com/(.*)$")]; export default Spotify; diff --git a/shared/editor/embeds/Tldraw.tsx b/shared/editor/embeds/Tldraw.tsx index 33acbaebc..ef1164200 100644 --- a/shared/editor/embeds/Tldraw.tsx +++ b/shared/editor/embeds/Tldraw.tsx @@ -14,6 +14,6 @@ function Tldraw(props: Props) { ); } -Tldraw.ENABLED = [new RegExp("https?://beta\\.tldraw\\.com/r/(.*)")]; +Tldraw.ENABLED = [new RegExp("^https?://beta\\.tldraw\\.com/r/(.*)")]; export default Tldraw;