提交 1e686201 编写于 作者: E Eric Frohnhoefer

Fix issue linkifying entities in Tweets with escaped html chars

Change-Id: I8781b02abf9e77d87c0c0f4def8e64030e861b35
上级 0050f60a
......@@ -150,7 +150,7 @@ final class TweetTextUtils {
}
}
// Once we've accumulated diffs, calc the offset
entity.start = entity.start - diff;
entity.start = entity.start - (diff + inDiff);
entity.end = entity.end - (diff + inDiff);
}
}
......
......@@ -32,6 +32,8 @@ public class TweetTextUtilsTest {
private static final String UNESCAPED_TWEET_TEXT = ">Hello there <\"What is a?\" &;";
private static final String ESCAPED_TWEET_TEXT
= "&gt;Hello there &lt;&quot;What is a?&quot; &;";
private static final String ESCAPED_TWEET_TEXT_WITH_EMOJI =
"\ud83d\udc69\ud83c\udffd\u200d\ud83d\udcbb, community \ud83d\udc93 &amp; https://t.co/oCkwy2C80m";
// test ported from:
// twitter-android/app/src/androidTest/java/com/twitter/library/util/EntitiesTests.java
......@@ -95,6 +97,21 @@ public class TweetTextUtilsTest {
assertEquals("&&&&gt&&lt&&amplt;", formattedTweetText.text);
}
@Test
public void testFormat_withEmojiAndEscapedHtml() {
final FormattedTweetText formattedTweetText = new FormattedTweetText();
final UrlEntity url = TestFixtures.newUrlEntity(24, 47);
formattedTweetText.urlEntities.add(FormattedUrlEntity.createFormattedUrlEntity(url));
final Tweet tweet = new TweetBuilder()
.setText(ESCAPED_TWEET_TEXT_WITH_EMOJI)
.build();
TweetTextUtils.format(formattedTweetText, tweet);
assertEquals(24, formattedTweetText.urlEntities.get(0).start);
assertEquals(47, formattedTweetText.urlEntities.get(0).end);
}
private Tweet setupTweetToBeFormatted() {
return new TweetBuilder().setText(ESCAPED_TWEET_TEXT).build();
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册