Skip to content

Commit

Permalink
Support x.com domain
Browse files Browse the repository at this point in the history
  • Loading branch information
gfscott committed Aug 14, 2023
1 parent 1d87ae2 commit a9c4b19
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 13 deletions.
2 changes: 1 addition & 1 deletion packages/twitter/lib/extractMatch.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const pattern = /<p>(?=(\s*))\1(?:<a [^>]*?>)??(?=(\s*))\2(?:https?:)??(?:\/\/)??(?:w{3}\.)??(?:twitter\.com)\/([a-zA-Z0-9_]{1,15})?(?:\/(?:status)\/)(\d+)?(?:[^\s<>]*)(?=(\s*))\5(?:<\/a>)??(?=(\s*))\6<\/p>/;
const pattern = /<p>(?=(\s*))\1(?:<a [^>]*?>)??(?=(\s*))\2(?:https?:)??(?:\/\/)??(?:w{3}\.)??(?:(?:twitter|x)\.com)\/([a-zA-Z0-9_]{1,15})?(?:\/(?:status)\/)(\d+)?(?:[^\s<>]*)(?=(\s*))\5(?:<\/a>)??(?=(\s*))\6<\/p>/;

module.exports = function(str) {
let match = str.match(pattern);
Expand Down
2 changes: 1 addition & 1 deletion packages/twitter/lib/spotPattern.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const pattern = /<p>(?=(\s*))\1(?:<a [^>]*?>)??(?=(\s*))\2(?:https?:)??(?:\/\/)??(?:w{3}\.)??(?:twitter\.com)\/([a-zA-Z0-9_]{1,15})?(?:\/(?:status)\/)(\d+)?(?:[^\s<>]*)(?=(\s*))\5(?:<\/a>)??(?=(\s*))\6<\/p>/g;
const pattern = /<p>(?=(\s*))\1(?:<a [^>]*?>)??(?=(\s*))\2(?:https?:)??(?:\/\/)??(?:w{3}\.)??(?:(?:twitter|x)\.com)\/([a-zA-Z0-9_]{1,15})?(?:\/(?:status)\/)(\d+)?(?:[^\s<>]*)(?=(\s*))\5(?:<\/a>)??(?=(\s*))\6<\/p>/g;

module.exports = function(str) {
return str.match(pattern);
Expand Down
66 changes: 55 additions & 11 deletions packages/twitter/test/inc/validStrings.js
Original file line number Diff line number Diff line change
@@ -1,46 +1,90 @@
module.exports = [
{
type: "User status, ideal",
type: "Twitter.com User status, ideal",
str: "https://twitter.com/SaraSoueidan/status/1289865845053652994",
},
{
type: "User status, with protocol, without secure, with slash, without www",
type: "Twitter.com User status, with protocol, without secure, with slash, without www",
str: "http://twitter.com/SaraSoueidan/status/1289865845053652994",
},
{
type: "User status, without protocol, with slash, without www",
type: "Twitter.com User status, without protocol, with slash, without www",
str: "//twitter.com/SaraSoueidan/status/1289865845053652994",
},
{
type: "User status, with protocol, with secure, with slash, with www",
type: "Twitter.com User status, with protocol, with secure, with slash, with www",
str: "https://www.twitter.com/SaraSoueidan/status/1289865845053652994",
},
{
type: "User status, with protocol, without secure, with slash, with www",
type: "Twitter.com User status, with protocol, without secure, with slash, with www",
str: "http://www.twitter.com/SaraSoueidan/status/1289865845053652994",
},
{
type: "User status, without protocol, with slash, with www",
type: "Twitter.com User status, without protocol, with slash, with www",
str: "//www.twitter.com/SaraSoueidan/status/1289865845053652994",
},
{
type: "User status, without protocol, without slash, without www",
type: "Twitter.com User status, without protocol, without slash, without www",
str: "twitter.com/SaraSoueidan/status/1289865845053652994",
},
{
type: "User status, ideal, with arbitrary param",
type: "Twitter.com User status, ideal, with arbitrary param",
str: "https://twitter.com/SaraSoueidan/status/1289865845053652994?foo",
},
{
type: "User status, ideal, with arbitrary key-value param",
type: "Twitter.com User status, ideal, with arbitrary key-value param",
str: "https://twitter.com/SaraSoueidan/status/1289865845053652994?foo=bar",
},
{
type: "User status, ideal, with arbitrary multiple params",
type: "Twitter.com User status, ideal, with arbitrary multiple params",
str: "https://twitter.com/SaraSoueidan/status/1289865845053652994?foo&bar",
},
{
type: "User status, ideal, with arbitrary multiple key-value params",
type: "Twitter.com User status, ideal, with arbitrary multiple key-value params",
str: "https://twitter.com/SaraSoueidan/status/1289865845053652994?foo=bar&baz=boo",
},
{
type: "X.com User status, ideal",
str: "https://x.com/SaraSoueidan/status/1289865845053652994",
},
{
type: "X.com User status, with protocol, without secure, with slash, without www",
str: "http://x.com/SaraSoueidan/status/1289865845053652994",
},
{
type: "X.com User status, without protocol, with slash, without www",
str: "//x.com/SaraSoueidan/status/1289865845053652994",
},
{
type: "X.com User status, with protocol, with secure, with slash, with www",
str: "https://www.x.com/SaraSoueidan/status/1289865845053652994",
},
{
type: "X.com User status, with protocol, without secure, with slash, with www",
str: "http://www.x.com/SaraSoueidan/status/1289865845053652994",
},
{
type: "X.com User status, without protocol, with slash, with www",
str: "//www.x.com/SaraSoueidan/status/1289865845053652994",
},
{
type: "X.com User status, without protocol, without slash, without www",
str: "x.com/SaraSoueidan/status/1289865845053652994",
},
{
type: "X.com User status, ideal, with arbitrary param",
str: "https://x.com/SaraSoueidan/status/1289865845053652994?foo",
},
{
type: "X.com User status, ideal, with arbitrary key-value param",
str: "https://x.com/SaraSoueidan/status/1289865845053652994?foo=bar",
},
{
type: "X.com User status, ideal, with arbitrary multiple params",
str: "https://x.com/SaraSoueidan/status/1289865845053652994?foo&bar",
},
{
type: "X.com User status, ideal, with arbitrary multiple key-value params",
str: "https://x.com/SaraSoueidan/status/1289865845053652994?foo=bar&baz=boo",
},
];

0 comments on commit a9c4b19

Please sign in to comment.