fix: mark nocookie youtube url as valid when parsing html (#4883)

This commit is contained in:
Lukas Hirt 2024-02-19 10:32:57 +01:00 committed by GitHub
parent 5a4c3baa06
commit 099e10df92
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 1 deletions

View File

@ -1,4 +1,4 @@
export const YOUTUBE_REGEX = /^(https?:\/\/)?(www\.|music\.)?(youtube\.com|youtu\.be)\/(?!channel\/)(?!@)(.+)?$/
export const YOUTUBE_REGEX = /^(https?:\/\/)?(www\.|music\.)?(youtube\.com|youtu\.be|youtube-nocookie\.com)\/(?!channel\/)(?!@)(.+)?$/
export const YOUTUBE_REGEX_GLOBAL = /^(https?:\/\/)?(www\.|music\.)?(youtube\.com|youtu\.be)\/(?!channel\/)(?!@)(.+)?$/g
export const isValidYoutubeUrl = (url: string) => {

View File

@ -57,4 +57,32 @@ describe('extension-youtube', () => {
getEditorEl()?.remove()
})
})
it('when nocookie youtube url is passed, still outputs html with iframe with the url', () => {
editor = new Editor({
element: createEditorEl(),
extensions: [
Document,
Text,
Paragraph,
Youtube,
],
content: {
type: 'doc',
content: [
{
type: 'youtube',
attrs: {
src: 'https://www.youtube-nocookie.com/embed/testvideoid',
},
},
],
},
})
expect(editor.getHTML()).to.include('https://www.youtube-nocookie.com/embed/testvideoid')
editor?.destroy()
getEditorEl()?.remove()
})
})