Commit aef712f6069ae8349c5d673af26bea779f186689
- Diff rendering mode:
- inline
- side by side
coefficient.rb
(5 / 1)
|   | |||
| 51 | 51 | # XXX: what if there is a # in the url? | |
| 52 | 52 | # XXX: + also breaks it | |
| 53 | 53 | ||
| 54 | new.gsub!(/(https?:\/\/[a-zA-Z0-9\/._%-]+)/, '<a href=""> | ||
| 54 | # maybe laconica-0.7.3/lib/util.php:common_replace_urls_callback() ? | ||
| 55 | new.gsub!(/(https?:\/\/[a-zA-Z0-9\/._%-+?#]+)/, '<a href="\1">\1</a>') | ||
| 55 | 56 | new.gsub!(/@([0-9a-zA-Z_]+)/, '@<a href="http://twitter.com/\1">\1</a>') | |
| 56 | 57 | ||
| 57 | 58 | return new | |
| … | … | ||
| 67 | 67 | ||
| 68 | 68 | # don't turn eg ' into a link. | |
| 69 | 69 | ||
| 70 | # hashtag regexp in laconica is /(?:^|\s)#([A-Za-z0-9_\-\.]{1,64})/ | ||
| 70 | 71 | new.gsub!(/#((?!39;)\S+)/, '#<a href="http://identi.ca/tag/\1">\1</a>') | |
| 72 | |||
| 73 | # group regexp in laconica is /(?:^|\s)!([A-Za-z0-9]{1,64}) | ||
| 71 | 74 | new.gsub!(/(?:!(\S+))/, '!<a href="http://identi.ca/group/\1">\1</a>') | |
| 72 | 75 | ||
| 73 | 76 | return new |
tests/unit.rb
(43 / 0)
|   | |||
| 1 | require 'test/unit' | ||
| 2 | require 'coefficient' | ||
| 3 | require 'shoulda' | ||
| 4 | |||
| 5 | class UnitTests < Test::Unit::TestCase | ||
| 6 | context "correctly parse urls" do | ||
| 7 | setup do | ||
| 8 | end | ||
| 9 | |||
| 10 | should "correctly parse basic URLs with no slash on the end" do | ||
| 11 | assert_equal "<a href=\"http://www.google.com\">http://www.google.com</a>", linkify("http://www.google.com") | ||
| 12 | end | ||
| 13 | |||
| 14 | should "correctly parse URLs with a slash on the end" do | ||
| 15 | assert_equal "<a href=\"http://www.google.com/\">http://www.google.com/</a>", linkify("http://www.google.com/") | ||
| 16 | end | ||
| 17 | |||
| 18 | should "correctly parse https urls" do | ||
| 19 | assert_equal "<a href=\"https://www.google.com/\">https://www.google.com/</a>", linkify("https://www.google.com/") | ||
| 20 | end | ||
| 21 | |||
| 22 | should "correctly parse urls with pages after a slash" do | ||
| 23 | assert_equal "<a href=\"https://www.google.com/link.html\">https://www.google.com/link.html</a>", linkify("https://www.google.com/link.html") | ||
| 24 | end | ||
| 25 | |||
| 26 | should "correctly parse urls with pages with ? in the url" do | ||
| 27 | assert_equal "<a href=\"https://www.google.com/?whatever.com\">https://www.google.com/?whatever.com</a>", linkify("https://www.google.com/?whatever.com") | ||
| 28 | end | ||
| 29 | |||
| 30 | should "correctly parse urls ending with a '.'" do | ||
| 31 | assert_equal "<a href=\"https://www.google.com/\">https://www.google.com/</a>", linkify("https://www.google.com/.") | ||
| 32 | end | ||
| 33 | |||
| 34 | should "correctly parse urls containing #." do | ||
| 35 | assert_equal "<a href=\"https://www.google.com/#anchor\">https://www.google.com/#anchor</a>", linkify("https://www.google.com/#anchor") | ||
| 36 | end | ||
| 37 | |||
| 38 | should "correctly parse urls containing +." do | ||
| 39 | assert_equal "<a href=\"https://www.google.com/+stuff\">https://www.google.com/+stuff</a>", linkify("https://www.google.com/+stuff") | ||
| 40 | end | ||
| 41 | |||
| 42 | end | ||
| 43 | end |

