From f61706c6e7a125afa94cccf6eccbbb55bc99f8be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20De=20Boey?= Date: Thu, 10 Oct 2019 18:10:30 +0200 Subject: [PATCH] fix(YouTube): Only support youtube.com or youtu.be urls --- src/YouTube.js | 4 ++-- src/__tests__/YouTube.js | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/YouTube.js b/src/YouTube.js index 152e94d9..e42ea170 100644 --- a/src/YouTube.js +++ b/src/YouTube.js @@ -4,8 +4,8 @@ export const shouldTransform = url => { const { host, pathname, searchParams } = new URL(url); return ( - host.endsWith('youtu.be') || - (host.endsWith('youtube.com') && + host === 'youtu.be' || + (host === 'youtube.com' && pathname.includes('/watch') && Boolean(searchParams.get('v'))) ); diff --git a/src/__tests__/YouTube.js b/src/__tests__/YouTube.js index 3e04185d..f1076382 100644 --- a/src/__tests__/YouTube.js +++ b/src/__tests__/YouTube.js @@ -17,6 +17,18 @@ cases( url: 'https://not-a-youtube-url.com', valid: false, }, + "non-YouTube url ending with 'youtu.be'": { + url: 'https://this-is-not-youtu.be', + valid: false, + }, + "non-YouTube url ending with 'youtube.com'": { + url: 'https://this-is-not-youtube.com', + valid: false, + }, + "non-YouTube url ending with 'youtube.com' and having a valid video path": { + url: 'https://this-is-not-youtube.com/watch?v=dQw4w9WgXcQ', + valid: false, + }, 'short url': { url: 'https://youtu.be/dQw4w9WgXcQ', valid: true,