-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Improve URL / tag / mention extraction when composing (#564)
Previous code used custom regular expressions to extract URLs, hashtags, and mentions from text while the user was writing a post. These were inconsistent with the ones that Mastodon uses so the derived character count could be wrong. As well as being visually incorrect this could prevent the user from posting a status that was within the length limit, or allow them to attempt to post a status that was over the length limit (which would then fail). Fix this by dropping the homegrown regular expressions and using the same text parsing library that Mastodon users; twitter-text. This has been converted to Kotlin and the functionality related to Twitter specific features has been removed. The hashtag handling has been adjusted, as Mastodon is more permissive about the positions where hashtags can appear than Twitter is, in particular, a hashtag does not need to be preceded with whitespace if the tag appears after some scripts, such as Hirigana.
- Loading branch information
1 parent
62fd47e
commit 2a4126a
Showing
8 changed files
with
2,266 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,9 +40,12 @@ class StatusLengthTest( | |
// "@user@server" should be treated as "@user" | ||
arrayOf("123 @[email protected]", 12), | ||
// URLs under 23 chars are treated as 23 chars | ||
arrayOf("123 http://example.url", 27), | ||
arrayOf("123 http://example.org", 27), | ||
// URLs over 23 chars are treated as 23 chars | ||
arrayOf("123 http://urlthatislongerthan23characters.example.org", 27), | ||
// URLs end when they should (the ")." should be part of the status | ||
// length, not considered to be part of the URL) | ||
arrayOf("test (https://example.com). test", 36), | ||
// Short hashtags are treated as is | ||
arrayOf("123 #basictag", 13), | ||
// Long hashtags are *also* treated as is (not treated as 23, like URLs) | ||
|
Oops, something went wrong.