Skip to content

Commit

Permalink
twitter: fix preview bug that auto-linked @-mentions inside URLs
Browse files Browse the repository at this point in the history
for snarfed/bridgy#527 (comment)

thanks again for reporting @jackysee!
  • Loading branch information
snarfed committed Nov 22, 2017
1 parent 48876f5 commit d76e923
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ Changelog
### 1.10 - unreleased
* Twitter:
* Update the publish character limit to 280. [Background.](https://twittercommunity.com/t/updating-the-character-limit-and-the-twitter-text-library/96425)
* Fix a [bug in `preview_create` that auto-linked @-mentions inside URLs](https://github.com/snarfed/bridgy/issues/527#issuecomment-346302800), e.g. Medium posts.

### 1.9 - 2017-10-24

Expand Down
12 changes: 12 additions & 0 deletions granary/test/test_twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -1779,6 +1779,18 @@ def test_ellipsize_real_tweet(self):
actual_preview = self.twitter.preview_create(obj, include_link=source.INCLUDE_LINK).content
self.assertEquals(preview, actual_preview)

def test_create_preview_dont_autolink_at_mentions_inside_urls(self):
"""Don't autolink @-mentions inside urls.
https://github.com/snarfed/bridgy/issues/527#issuecomment-346302800
"""
obj = copy.deepcopy(OBJECT)
del obj['image']
obj['content'] = u'時空黑洞都出現了,非常歡樂!LOL https://medium.com/@abc/xyz'
self.assertEquals(
u'時空黑洞都出現了,非常歡樂!LOL <a href="https://medium.com/@abc/xyz">medium.com/@abc/xyz</a>',
self.twitter.preview_create(obj).content)

def test_tweet_article_has_different_format(self):
"""Articles are published with a slightly different format:
"The Title: url", instead of "The Title (url)"
Expand Down
2 changes: 1 addition & 1 deletion granary/twitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@
# username requirements and limits:
# https://support.twitter.com/articles/101299#error
# http://stackoverflow.com/a/13396934/186123
MENTION_RE = re.compile(r'(^|[^@\w])@(\w{1,15})\b', re.UNICODE)
MENTION_RE = re.compile(r'(^|[^\w@/\!?=&])@(\w{1,15})\b', re.UNICODE)

# hashtag requirements and limits:
# https://support.twitter.com/articles/370610
Expand Down

0 comments on commit d76e923

Please sign in to comment.