Skip to content

Commit

Permalink
add vimeo.work and videoji.cn to allowed vimeo domains (#1044)
Browse files Browse the repository at this point in the history
  • Loading branch information
aaronm67 authored Aug 8, 2024
1 parent c1c8aa0 commit 0d61097
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
17 changes: 12 additions & 5 deletions src/lib/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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';
Expand Down
12 changes: 11 additions & 1 deletion test/functions-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) => {
Expand All @@ -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');
Expand All @@ -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) => {
Expand Down

0 comments on commit 0d61097

Please sign in to comment.