Created
June 16, 2011 07:25
-
-
Save tigris/1028830 to your computer and use it in GitHub Desktop.
twitter-text-rb failure on double greater than
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
diff --git a/lib/autolink.rb b/lib/autolink.rb | |
index 178e92f..dcdbc2a 100644 | |
--- a/lib/autolink.rb | |
+++ b/lib/autolink.rb | |
@@ -78,12 +78,10 @@ module Twitter | |
new_text = "" | |
# this -1 flag allows strings ending in ">" to work | |
- text.split(/[<>]/, -1).each_with_index do |chunk, index| | |
- if index != 0 | |
- new_text << ((index % 2 == 0) ? ">" : "<") | |
- end | |
- | |
- if index % 4 != 0 | |
+ text.split(/([<>])/, -1).each_with_index do |chunk, index| | |
+ if index != 0 and chunk.match(/[<>]/) | |
+ new_text << chunk | |
+ elsif index % 8 != 0 | |
new_text << chunk | |
else | |
new_text << chunk.gsub(Twitter::Regex[:auto_link_usernames_or_lists]) do |
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
diff --git a/autolink.yml b/autolink.yml | |
index f4c3f0b..9a0eb07 100644 | |
--- a/autolink.yml | |
+++ b/autolink.yml | |
@@ -444,3 +444,7 @@ tests: | |
- description: "Does not allow an XSS after an @" | |
text: "See: http://x.xx/@\"style=\"color:pink\"onmouseover=alert(1)//" | |
expected: "See: <a href=\"http://x.xx/\">http://x.xx/</a>@\"style=\"color:pink\"onmouseover=alert(1)//" | |
+ | |
+ - description: "Correctly handles double greater than signs" | |
+ text: "I love double >> greater than signs." | |
+ expected: "I love double >> greater than signs." | |
+ | |
+ - description: "Correctly handles triple greater than signs with username" | |
+ text: "I love triple >>> greater than signs with @username usernames." | |
+ expected: "I love triple >>> greater than signs with @<a class=\"tweet-url username\" href=\"http://twitter.com/username\">username</a> usernames." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: This fix breaks the test that deals with @foo being part of an existing URL in the tweet content. I.e. linkage should not get converted to a twitter link.