Skip to content

Commit

Permalink
Merge pull request #66 from micnews/twitter-query
Browse files Browse the repository at this point in the history
Remove query string from tweet id
  • Loading branch information
ryanscottaudio authored Dec 16, 2016
2 parents f2aeb00 + 0c7f6c5 commit 55a09e8
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/types/twitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions test/html-parse-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,27 @@ test('parse() tweet - no id', t => {
t.deepEqual(actual, expected);
});

test('parse() tweet - href has query string', t => {
const input = `<blockquote class="twitter-tweet" data-lang="en"><p lang="en" dir="ltr">GIF vs. JIF… This <a href="https://t.co/qFAHWgdbL6">pic.twitter.com/qFAHWgdbL6</a></p>&mdash; Matt (foo) Navarra (@MattNavarra) <a href="https://twitter.com/MattNavarra/status/684690494841028608?ref_src=twsrc%5Etfw">January 6, 2016</a></blockquote><script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>`;
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 = `<iframe src="http://instagram.com/p/fdx1CSuEPV/embed"></iframe>`;
const actual = parse(input);
Expand Down

0 comments on commit 55a09e8

Please sign in to comment.