Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #11 from jamis/master

Play nicely with non-latin characters in autolinked urls
  • Loading branch information...
commit 509704435099bc2185b3728c4657195f6fadda94 2 parents a065b4b + 91a59b5
@xuanxu xuanxu authored
Showing with 7 additions and 2 deletions.
  1. +6 −2 lib/rails_autolink/helpers.rb
  2. +1 −0  test/test_rails_autolink.rb
View
8 lib/rails_autolink/helpers.rb
@@ -1,3 +1,5 @@
+# encoding: utf-8
+
module RailsAutolink
require 'active_support/core_ext/object/blank'
require 'active_support/core_ext/array/extract_options'
@@ -80,6 +82,8 @@ def auto_link(text, *args, &block)#link = :all, html = {}, &block)
BRACKETS = { ']' => '[', ')' => '(', '}' => '{' }
+ WORD_PATTERN = RUBY_VERSION < '1.9' ? '\w' : '\p{Word}'
+
# Turns all urls into clickable links. If a block is given, each url
# is yielded and the result is used as the link text.
def auto_link_urls(text, html_options = {}, options = {})
@@ -93,7 +97,7 @@ def auto_link_urls(text, html_options = {}, options = {})
href
else
# don't include trailing punctuation character as part of the URL
- while href.sub!(/[^\w\/-]$/, '')
+ while href.sub!(/[^#{WORD_PATTERN}\/-]$/, '')
punctuation.push $&
if opening = BRACKETS[punctuation.last] and href.scan(opening).size > href.scan(punctuation.last).size
href << punctuation.pop
@@ -149,4 +153,4 @@ def conditional_html_safe(target, condition)
end
end
end
-end
+end
View
1  test/test_rails_autolink.rb
@@ -298,6 +298,7 @@ def test_auto_link_parsing
http://connect.oraclecorp.com/search?search[q]=green+france&search[type]=Group
http://of.openfoundry.org/projects/492/download#4th.Release.3
http://maps.google.co.uk/maps?f=q&q=the+london+eye&ie=UTF8&ll=51.503373,-0.11939&spn=0.007052,0.012767&z=16&iwloc=A
+ http://около.кола/колокола
)
urls.each do |url|
Please sign in to comment.
Something went wrong with that request. Please try again.