Skip to content

Commit

Permalink
fix(YouTube): Only support youtube.com or youtu.be urls
Browse files Browse the repository at this point in the history
MichaelDeBoey committed Oct 10, 2019
1 parent 3c51a0e commit f61706c
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/YouTube.js
Original file line number Diff line number Diff line change
@@ -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')))
);
12 changes: 12 additions & 0 deletions src/__tests__/YouTube.js
Original file line number Diff line number Diff line change
@@ -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,

0 comments on commit f61706c

Please sign in to comment.