From 0d6109785569003b1ca4a218dcf87653d7c35665 Mon Sep 17 00:00:00 2001 From: Aaron Marasco Date: Thu, 8 Aug 2024 09:18:23 -0400 Subject: [PATCH] add vimeo.work and videoji.cn to allowed vimeo domains (#1044) --- src/lib/functions.js | 17 ++++++++++++----- test/functions-test.js | 12 +++++++++++- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/lib/functions.js b/src/lib/functions.js index b3eb08eda..3d5132abf 100755 --- a/src/lib/functions.js +++ b/src/lib/functions.js @@ -58,7 +58,7 @@ export function isInteger(value) { * @return {boolean} */ export function isVimeoUrl(url) { - return (/^(https?:)?\/\/((((player|www)\.)?vimeo\.com)|((player\.)?[a-zA-Z0-9-]+\.videoji\.hk))(?=$|\/)/).test(url); + return (/^(https?:)?\/\/((((player|www)\.)?vimeo\.com)|((player\.)?[a-zA-Z0-9-]+\.(videoji\.(hk|cn)|vimeo\.work)))(?=$|\/)/).test(url); } /** @@ -68,16 +68,23 @@ export function isVimeoUrl(url) { * @return {boolean} */ export function isVimeoEmbed(url) { - const expr = /^https:\/\/player\.((vimeo\.com)|([a-zA-Z0-9-]+\.videoji\.hk))\/video\/\d+/; + const expr = /^https:\/\/player\.((vimeo\.com)|([a-zA-Z0-9-]+\.(videoji\.(hk|cn)|vimeo\.work)))\/video\/\d+/; return expr.test(url); } export function getOembedDomain(url) { const match = (url || '').match(/^(?:https?:)?(?:\/\/)?([^/?]+)/); const domain = ((match && match[1]) || '').replace('player.', ''); - - if (domain.endsWith('.videoji.hk')) { - return domain; + const customDomains = [ + '.videoji.hk', + '.vimeo.work', + '.videoji.cn' + ]; + + for (const customDomain of customDomains) { + if (domain.endsWith(customDomain)) { + return domain; + } } return 'vimeo.com'; diff --git a/test/functions-test.js b/test/functions-test.js index c25ccc748..552205f23 100755 --- a/test/functions-test.js +++ b/test/functions-test.js @@ -40,6 +40,12 @@ test('isVimeoUrl identifies *.vimeo.com only', (t) => { t.true(isVimeoUrl('https://www.vimeo.com') === true); t.true(isVimeoUrl('//www.vimeo.com') === true); t.true(isVimeoUrl('http://player.vimeo.com') === true); + t.true(isVimeoUrl('http://player.subdomain.videoji.cn') === true); + t.true(isVimeoUrl('http://player.subdomain.videoji.cn/video/12345') === true); + t.true(isVimeoUrl('http://player.subdomain.videoji.cn/video/12345?h=a1b2c3d4') === true); + t.true(isVimeoUrl('http://player.subdomain.vimeo.work') === true); + t.true(isVimeoUrl('http://player.subdomain.vimeo.work/video/12345') === true); + t.true(isVimeoUrl('http://player.subdomain.vimeo.work/video/12345?h=a1b2c3d4') === true); t.true(isVimeoUrl('http://player.subdomain.videoji.hk') === true); t.true(isVimeoUrl('http://player.subdomain.videoji.hk/video/12345') === true); t.true(isVimeoUrl('http://player.subdomain.videoji.hk/video/12345?h=a1b2c3d4') === true); @@ -64,6 +70,9 @@ test('isVimeoEmbed identifies Vimeo embeds only', (t) => { t.true(isVimeoEmbed('http://player.subdomain.videoji.hk/video/76979871?h=8272103f6e') === false); t.true(isVimeoEmbed('https://player.subdomain.videoji.hk/video/76979871?h=8272103f6e') === true); t.true(isVimeoEmbed('http2://not-vimeo.com/video/76979871') === false); + t.true(isVimeoEmbed('https://player.subdomain.videoji.cn/video/76979871?h=8272103f6e') === true); + t.true(isVimeoEmbed('https://player.subdomain.vimeo.work/video/76979871?h=8272103f6e') === true); + t.true(isVimeoEmbed('http2://not-vimeo.com/video/76979871') === false); }); test('getOembedDomain correctly returns a domain from a url', (t) => { @@ -72,6 +81,8 @@ test('getOembedDomain correctly returns a domain from a url', (t) => { t.true(getOembedDomain('http://player.vimeo.com/video/76979871?h=8272103f6e') === 'vimeo.com'); t.true(getOembedDomain('http://player.subdomain.videoji.hk/video/76979871?h=8272103f6e') === 'subdomain.videoji.hk'); t.true(getOembedDomain('https://player.subdomain.videoji.hk/video/76979871?h=8272103f6e') === 'subdomain.videoji.hk'); + t.true(getOembedDomain('https://player.subdomain.videoji.cn/video/76979871?h=8272103f6e') === 'subdomain.videoji.cn'); + t.true(getOembedDomain('https://player.subdomain.vimeo.work/video/76979871?h=8272103f6e') === 'subdomain.vimeo.work'); t.true(getOembedDomain('http2://not-vimeo.com/video/76979871') === 'vimeo.com'); t.true(getOembedDomain(null) === 'vimeo.com'); t.true(getOembedDomain(undefined) === 'vimeo.com'); @@ -82,7 +93,6 @@ test('getVimeoUrl correctly returns a url from the embed parameters', (t) => { t.true(getVimeoUrl({ id: 445351154 }) === 'https://vimeo.com/445351154'); t.true(getVimeoUrl({ url: 'http://vimeo.com/445351154' }) === 'https://vimeo.com/445351154'); t.true(getVimeoUrl({ url: 'https://vimeo.com/445351154' }) === 'https://vimeo.com/445351154'); - }); test('getVimeoUrl throws when the required keys don’t exist', (t) => {