Update URL parser to handle 'x.com' links
This commit is contained in:
parent
0907fe7fa8
commit
392e836689
@ -257,7 +257,7 @@ func TestSearchRedirectOnUserFeedLink(t *testing.T) {
|
||||
assert.Equal(resp.Header.Get("Location"), "/agsdf")
|
||||
|
||||
// "With Replies" page
|
||||
resp = do_request(httptest.NewRequest("GET", fmt.Sprintf("/search/%s", url.PathEscape("https://twitter.com/agsdf/with_replies")), nil))
|
||||
resp = do_request(httptest.NewRequest("GET", fmt.Sprintf("/search/%s", url.PathEscape("https://x.com/agsdf/with_replies")), nil))
|
||||
assert.Equal(resp.StatusCode, 302)
|
||||
assert.Equal(resp.Header.Get("Location"), "/agsdf")
|
||||
|
||||
|
@ -97,17 +97,15 @@ func get_thumbnail_local_path(remote_url string) string {
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Given an URL, try to parse it as a tweet url.
|
||||
* The bool is an `is_ok` value; true if the parse was successful, false if it didn't match
|
||||
*/
|
||||
// Given an URL, try to parse it as a tweet url.
|
||||
// The bool is an `is_ok` value; true if the parse was successful, false if it didn't match
|
||||
func TryParseTweetUrl(s string) (UserHandle, TweetID, bool) {
|
||||
parsed_url, err := url.Parse(s)
|
||||
if err != nil {
|
||||
return UserHandle(""), TweetID(0), false
|
||||
}
|
||||
|
||||
if parsed_url.Host != "twitter.com" && parsed_url.Host != "mobile.twitter.com" {
|
||||
if parsed_url.Host != "twitter.com" && parsed_url.Host != "mobile.twitter.com" && parsed_url.Host != "x.com" {
|
||||
return UserHandle(""), TweetID(0), false
|
||||
}
|
||||
|
||||
|
@ -123,6 +123,12 @@ func TestParseTweetUrl(t *testing.T) {
|
||||
assert.Equal(UserHandle("APhilosophae"), handle)
|
||||
assert.Equal(TweetID(1497720548540964864), id)
|
||||
|
||||
// Test a `x.com` url
|
||||
handle, id, is_ok = TryParseTweetUrl("https://x.com/brutedeforce/status/1579695139425222657?s=46")
|
||||
assert.True(is_ok)
|
||||
assert.Equal(UserHandle("brutedeforce"), handle)
|
||||
assert.Equal(TweetID(1579695139425222657), id)
|
||||
|
||||
// Test invalid url
|
||||
_, _, is_ok = TryParseTweetUrl("https://twitter.com/NerdNoticing/status/1263192389050654720s=20")
|
||||
assert.False(is_ok)
|
||||
|
Loading…
x
Reference in New Issue
Block a user