From 0c7f6c54ac0e274302dc37989b72cac2f5523d81 Mon Sep 17 00:00:00 2001 From: ryanscottaudio Date: Fri, 16 Dec 2016 14:08:26 -0500 Subject: [PATCH] Remove query string from tweet id --- lib/types/twitter.js | 2 +- test/html-parse-test.js | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/types/twitter.js b/lib/types/twitter.js index bbd7606..bd3ab20 100644 --- a/lib/types/twitter.js +++ b/lib/types/twitter.js @@ -43,7 +43,7 @@ export const parse = ([elm]) => { } const url = aElm.getAttribute('href'); - const id = last(url.split('/').filter(Boolean)); + const id = last(url.split('/').filter(Boolean)).split('?')[0]; const date = aElm.childNodes.length > 0 ? aElm.childNodes[0].data : ''; const user = getUser(elm); const text = getText(elm); diff --git a/test/html-parse-test.js b/test/html-parse-test.js index ad6763d..860f95f 100644 --- a/test/html-parse-test.js +++ b/test/html-parse-test.js @@ -281,6 +281,27 @@ test('parse() tweet - no id', t => { t.deepEqual(actual, expected); }); +test('parse() tweet - href has query string', t => { + const input = `

GIF vs. JIF… This pic.twitter.com/qFAHWgdbL6

— Matt (foo) Navarra (@MattNavarra) January 6, 2016
`; + const actual = parse(input); + const expected = { + type: 'twitter', + embedAs: 'tweet', + text: [ + {content: 'GIF vs. JIF… This ', href: null}, + {content: 'pic.twitter.com/qFAHWgdbL6', href: 'https://t.co/qFAHWgdbL6'} + ], + url: 'https://twitter.com/MattNavarra/status/684690494841028608?ref_src=twsrc%5Etfw', + date: 'January 6, 2016', + user: { + slug: 'MattNavarra', + name: 'Matt (foo) Navarra' + }, + id: '684690494841028608' + }; + t.deepEqual(actual, expected); +}); + test('parse() instagram http iframe', t => { const input = ``; const actual = parse(input);