Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove query string from tweet id #66

Merged
merged 1 commit into from
Dec 16, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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