From 928a626c2e82eb2663e16800a87b1c34c0ab83d5 Mon Sep 17 00:00:00 2001 From: Hailey <153161762+haileyok@users.noreply.github.com> Date: Mon, 8 Jan 2024 13:55:48 -0800 Subject: [PATCH] support intl tenor links (#2438) * support intl tenor links * update test cases --- __tests__/lib/string.test.ts | 8 ++++++++ src/lib/strings/embed-player.ts | 7 +++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/__tests__/lib/string.test.ts b/__tests__/lib/string.test.ts index 89df7a6b..edddcb3e 100644 --- a/__tests__/lib/string.test.ts +++ b/__tests__/lib/string.test.ts @@ -455,6 +455,7 @@ describe('parseEmbedPlayerFromUrl', () => { 'https://tenor.com/notView/gifId', 'https://tenor.com/view', 'https://tenor.com/view/gifId.gif', + 'https://tenor.com/intl/view/gifId.gif', ] const outputs = [ @@ -742,6 +743,13 @@ describe('parseEmbedPlayerFromUrl', () => { hideDetails: true, playerUri: 'https://tenor.com/view/gifId.gif', }, + { + type: 'tenor_gif', + source: 'tenor', + isGif: true, + hideDetails: true, + playerUri: 'https://tenor.com/intl/view/gifId.gif', + }, ] it('correctly grabs the correct id from uri', () => { diff --git a/src/lib/strings/embed-player.ts b/src/lib/strings/embed-player.ts index b27fd9e7..0f97eb08 100644 --- a/src/lib/strings/embed-player.ts +++ b/src/lib/strings/embed-player.ts @@ -319,9 +319,12 @@ export function parseEmbedPlayerFromUrl( } if (urlp.hostname === 'tenor.com' || urlp.hostname === 'www.tenor.com') { - const [_, path, filename] = urlp.pathname.split('/') + const [_, pathOrIntl, pathOrFilename, intlFilename] = + urlp.pathname.split('/') + const isIntl = pathOrFilename === 'view' + const filename = isIntl ? intlFilename : pathOrFilename - if (path === 'view' && filename) { + if ((pathOrIntl === 'view' || pathOrFilename === 'view') && filename) { const includesExt = filename.split('.').pop() === 'gif' return {