bool rinku_isspace(char c);
bool rinku_ispunct(char c);
bool rinku_isdigit(char c);
bool rinku_isalpha(char c);
bool rinku_isalnum(char c);
int32_t utf8proc_rewind(const uint8_t *data, size_t pos);
int32_t utf8proc_next(const uint8_t *str, size_t *pos);
int32_t utf8proc_back(const uint8_t *data, size_t *pos);
size_t utf8proc_find_space(const uint8_t *str, size_t pos, size_t size);
int32_t utf8proc_open_paren_character(int32_t cclose);
bool utf8proc_is_space(int32_t uc);
bool utf8proc_is_punctuation(int32_t uc);
#endif
rinku-2.0.6/lib/ 0000775 0000000 0000000 00000000000 13457456033 0013427 5 ustar 00root root 0000000 0000000 rinku-2.0.6/lib/rails_rinku.rb 0000664 0000000 0000000 00000001565 13457456033 0016305 0 ustar 00root root 0000000 0000000 require 'rinku'
module RailsRinku
def rinku_auto_link(text, *args, &block)
return '' if text.blank?
options = args.size == 2 ? {} : args.extract_options!
unless args.empty?
options[:link] = args[0] || :all
options[:html] = args[1] || {}
options[:skip] = args[2]
end
options.reverse_merge!(:link => :all, :html => {})
text = h(text) unless text.html_safe?
tag_options_method = if Gem::Version.new(Rails.version) >= Gem::Version.new("5.1")
# Rails >= 5.1
tag_builder.method(:tag_options)
else
# Rails <= 5.0
method(:tag_options)
end
Rinku.auto_link(
text,
options[:link],
tag_options_method.call(options[:html]),
options[:skip],
&block
).html_safe
end
end
module ActionView::Helpers::TextHelper
include RailsRinku
alias_method :auto_link, :rinku_auto_link
end
rinku-2.0.6/lib/rinku.rb 0000664 0000000 0000000 00000000205 13457456033 0015101 0 ustar 00root root 0000000 0000000 module Rinku
VERSION = "2.0.6"
class << self
attr_accessor :skip_tags
end
self.skip_tags = nil
end
require 'rinku.so'
rinku-2.0.6/rinku.gemspec 0000664 0000000 0000000 00000002136 13457456033 0015360 0 ustar 00root root 0000000 0000000 Gem::Specification.new do |s|
s.name = 'rinku'
s.version = '2.0.6'
s.summary = "Mostly autolinking"
s.description = <<-EOF
A fast and very smart autolinking library that
acts as a drop-in replacement for Rails `auto_link`
EOF
s.email = 'vicent@github.com'
s.homepage = 'https://github.com/vmg/rinku'
s.authors = ["Vicent Marti"]
s.license = 'ISC'
# = MANIFEST =
s.files = %w[
COPYING
README.markdown
Rakefile
ext/rinku/autolink.c
ext/rinku/autolink.h
ext/rinku/buffer.c
ext/rinku/buffer.h
ext/rinku/extconf.rb
ext/rinku/rinku.c
ext/rinku/rinku.h
ext/rinku/rinku_rb.c
ext/rinku/utf8.c
ext/rinku/utf8.h
lib/rails_rinku.rb
lib/rinku.rb
rinku.gemspec
test/autolink_test.rb
]
# = MANIFEST =
s.test_files = ["test/autolink_test.rb"]
s.extra_rdoc_files = ["COPYING"]
s.extensions = ["ext/rinku/extconf.rb"]
s.require_paths = ["lib"]
s.add_development_dependency "rake"
s.add_development_dependency "rake-compiler"
s.add_development_dependency "minitest", ">= 5.0"
s.required_ruby_version = '>= 2.0.0'
end
rinku-2.0.6/test/ 0000775 0000000 0000000 00000000000 13457456033 0013640 5 ustar 00root root 0000000 0000000 rinku-2.0.6/test/autolink_test.rb 0000664 0000000 0000000 00000045635 13457456033 0017067 0 ustar 00root root 0000000 0000000 require 'bundler/setup'
$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
require 'minitest/autorun'
require 'cgi'
require 'uri'
require 'rinku'
class RinkuAutoLinkTest < Minitest::Test
def generate_result(link_text, href = nil)
href ||= link_text
href = "http://" + href unless href =~ %r{\A(\w+://|mailto:)}
%{#{CGI.escapeHTML link_text}}
end
def assert_linked(expected, url)
assert_equal expected, Rinku.auto_link(url)
end
def test_segfault
Rinku.auto_link("a+b@d.com+e@f.com", :all)
end
def test_escapes_quotes
assert_linked %(http://website.com/"onmouseover=document.body.style.backgroundColor="pink";//),
%(http://website.com/"onmouseover=document.body.style.backgroundColor="pink";//)
end
def test_global_skip_tags
assert_nil Rinku.skip_tags
Rinku.skip_tags = ['pre']
assert_equal Rinku.skip_tags, ['pre']
Rinku.skip_tags = ['pa']
url = 'This is just a http://www.pokemon.com test'
assert_equal Rinku.auto_link(url), url
Rinku.skip_tags = nil
refute_equal Rinku.auto_link(url), url
end
def test_auto_link_with_single_trailing_punctuation_and_space
url = "http://www.youtube.com"
url_result = generate_result(url)
assert_equal url_result, Rinku.auto_link(url)
["?", "!", ".", ",", ":"].each do |punc|
assert_equal "link: #{url_result}#{punc} foo?", Rinku.auto_link("link: #{url}#{punc} foo?")
end
end
def test_terminates_on_ampersand
url = "http://example.com"
assert_linked "hello '#{url}' hello", "hello '#{url}' hello"
end
def test_does_not_segfault
assert_linked "< this is just a test", "< this is just a test"
end
def test_skips_tags
html = <<-html
This is just a test. http://www.pokemon.com
More test
http://www.amd.com
CODE www.less.es
html
result = <<-result
This is just a test. http://www.pokemon.com
More test
http://www.amd.com
CODE www.less.es
result
assert_equal result, Rinku.auto_link(html, :all, nil, ["div", "a"])
end
def test_auto_link_with_brackets
link1_raw = 'http://en.wikipedia.org/wiki/Sprite_(computer_graphics)'
link1_result = generate_result(link1_raw)
assert_equal link1_result, Rinku.auto_link(link1_raw)
assert_equal "(link: #{link1_result})", Rinku.auto_link("(link: #{link1_raw})")
link2_raw = 'http://en.wikipedia.org/wiki/Sprite_[computer_graphics]'
link2_result = generate_result(link2_raw)
assert_equal link2_result, Rinku.auto_link(link2_raw)
assert_equal "[link: #{link2_result}]", Rinku.auto_link("[link: #{link2_raw}]")
link3_raw = 'http://en.wikipedia.org/wiki/Sprite_{computer_graphics}'
link3_result = generate_result(link3_raw)
assert_equal link3_result, Rinku.auto_link(link3_raw)
assert_equal "{link: #{link3_result}}", Rinku.auto_link("{link: #{link3_raw}}")
end
def test_auto_link_with_multiple_trailing_punctuations
url = "http://youtube.com"
url_result = generate_result(url)
assert_equal url_result, Rinku.auto_link(url)
assert_equal "(link: #{url_result}).", Rinku.auto_link("(link: #{url}).")
end
def test_auto_link_with_block
url = "http://api.rubyonrails.com/Foo.html"
email = "fantabulous@shiznadel.ic"
assert_equal %(#{url[0...7]}...
#{email[0...7]}...
), Rinku.auto_link("#{url}
#{email}
") { |_url| _url[0...7] + '...'}
end
def test_auto_link_with_block_with_html
pic = "http://example.com/pic.png"
url = "http://example.com/album?a&b=c"
expect = %(My pic:
-- full album here #{generate_result(url)})
text = "My pic: #{pic} -- full album here #{CGI.escapeHTML url}"
assert_equal expect, Rinku.auto_link(text) { |link|
if link =~ /\.(jpg|gif|png|bmp|tif)$/i
%(
)
else
link
end
}
end
def test_auto_link_already_linked
linked1 = generate_result('Ruby On Rails', 'http://www.rubyonrails.com')
linked2 = %('www.example.com')
linked3 = %('www.example.com')
linked4 = %('www.example.com')
linked5 = %('close www.example.com')
assert_equal linked1, Rinku.auto_link(linked1)
assert_equal linked2, Rinku.auto_link(linked2)
assert_equal linked3, Rinku.auto_link(linked3)
assert_equal linked4, Rinku.auto_link(linked4)
assert_equal linked5, Rinku.auto_link(linked5)
linked_email = %Q(Mail me)
assert_equal linked_email, Rinku.auto_link(linked_email)
end
def test_auto_link_at_eol
url1 = "http://api.rubyonrails.com/Foo.html"
url2 = "http://www.ruby-doc.org/core/Bar.html"
assert_equal %(#{url1}
#{url2}
), Rinku.auto_link("#{url1}
#{url2}
")
end
def test_block
link = Rinku.auto_link("Find ur favorite pokeman @ http://www.pokemon.com") do |url|
assert_equal url, "http://www.pokemon.com"
"POKEMAN WEBSITE"
end
assert_equal link, "Find ur favorite pokeman @ POKEMAN WEBSITE"
end
def test_autolink_works
url = "http://example.com/"
assert_linked "#{url}", url
end
def test_autolink_options_for_short_domains
url = "http://google"
linked_url = "#{url}"
flags = Rinku::AUTOLINK_SHORT_DOMAINS
# Specifying use short_domains in the args
url = "http://google"
linked_url = "#{url}"
assert_equal Rinku.auto_link(url, nil, nil, nil, flags), linked_url
# Specifying no short_domains in the args
url = "http://google"
linked_url = "#{url}"
assert_equal Rinku.auto_link(url, nil, nil, nil, 0), url
end
def test_not_autolink_www
assert_linked "Awww... man", "Awww... man"
end
def test_does_not_terminate_on_dash
url = "http://example.com/Notification_Center-GitHub-20101108-140050.jpg"
assert_linked "#{url}", url
end
def test_does_not_include_trailing_gt
url = "http://example.com"
assert_linked "<#{url}>", "<#{url}>"
end
def test_links_with_anchors
url = "https://github.com/github/hubot/blob/master/scripts/cream.js#L20-20"
assert_linked "#{url}", url
end
def test_links_like_rails
urls = %w(http://www.rubyonrails.com
http://www.rubyonrails.com:80
http://www.rubyonrails.com/~minam
https://www.rubyonrails.com/~minam
http://www.rubyonrails.com/~minam/url%20with%20spaces
http://www.rubyonrails.com/foo.cgi?something=here
http://www.rubyonrails.com/foo.cgi?something=here&and=here
http://www.rubyonrails.com/contact;new
http://www.rubyonrails.com/contact;new%20with%20spaces
http://www.rubyonrails.com/contact;new?with=query&string=params
http://www.rubyonrails.com/~minam/contact;new?with=query&string=params
http://en.wikipedia.org/wiki/Wikipedia:Today%27s_featured_picture_%28animation%29/January_20%2C_2007
http://www.mail-archive.com/rails@lists.rubyonrails.org/
http://www.amazon.com/Testing-Equal-Sign-In-Path/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1198861734&sr=8-1
http://en.wikipedia.org/wiki/Sprite_(computer_graphics)
http://en.wikipedia.org/wiki/Texas_hold%27em
https://www.google.com/doku.php?id=gps:resource:scs:start
)
urls.each do |url|
assert_linked %(#{CGI.escapeHTML url}), CGI.escapeHTML(url)
end
end
def test_links_like_autolink_rails
email_raw = 'david@loudthinking.com'
email_result = %{#{email_raw}}
email2_raw = '+david@loudthinking.com'
email2_result = %{#{email2_raw}}
link_raw = 'http://www.rubyonrails.com'
link_result = %{#{link_raw}}
link2_raw = 'www.rubyonrails.com'
link2_result = %{#{link2_raw}}
link3_raw = 'http://manuals.ruby-on-rails.com/read/chapter.need_a-period/103#page281'
link3_result = %{#{link3_raw}}
link4_raw = CGI.escapeHTML 'http://foo.example.com/controller/action?parm=value&p2=v2#anchor123'
link4_result = %{#{link4_raw}}
link5_raw = 'http://foo.example.com:3000/controller/action'
link5_result = %{#{link5_raw}}
link6_raw = 'http://foo.example.com:3000/controller/action+pack'
link6_result = %{#{link6_raw}}
link7_raw = CGI.escapeHTML 'http://foo.example.com/controller/action?parm=value&p2=v2#anchor-123'
link7_result = %{#{link7_raw}}
link8_raw = 'http://foo.example.com:3000/controller/action.html'
link8_result = %{#{link8_raw}}
link9_raw = 'http://business.timesonline.co.uk/article/0,,9065-2473189,00.html'
link9_result = %{#{link9_raw}}
link10_raw = 'http://www.mail-archive.com/ruby-talk@ruby-lang.org/'
link10_result = %{#{link10_raw}}
assert_linked %(Go to #{link_result} and say hello to #{email_result}), "Go to #{link_raw} and say hello to #{email_raw}"
assert_linked %(Link #{link_result}
), "Link #{link_raw}
"
assert_linked %(#{link_result} Link
), "#{link_raw} Link
"
assert_linked %(Go to #{link_result}.), %(Go to #{link_raw}.)
assert_linked %(Go to #{link_result}, then say hello to #{email_result}.
), %(Go to #{link_raw}, then say hello to #{email_raw}.
)
assert_linked %(Link #{link2_result}
), "Link #{link2_raw}
"
assert_linked %(#{link2_result} Link
), "#{link2_raw} Link
"
assert_linked %(Go to #{link2_result}.), %(Go to #{link2_raw}.)
assert_linked %(Say hello to #{email_result}, then go to #{link2_result},
), %(Say hello to #{email_raw}, then go to #{link2_raw},
)
assert_linked %(Link #{link3_result}
), "Link #{link3_raw}
"
assert_linked %(#{link3_result} Link
), "#{link3_raw} Link
"
assert_linked %(Go to #{link3_result}.), %(Go to #{link3_raw}.)
assert_linked %(Go to #{link3_result}. seriously, #{link3_result}? i think I'll say hello to #{email_result}. instead.
), %(Go to #{link3_raw}. seriously, #{link3_raw}? i think I'll say hello to #{email_raw}. instead.
)
assert_linked %(Link #{link4_result}
), "Link #{link4_raw}
"
assert_linked %(#{link4_result} Link
), "#{link4_raw} Link
"
assert_linked %(#{link5_result} Link
), "#{link5_raw} Link
"
assert_linked %(#{link6_result} Link
), "#{link6_raw} Link
"
assert_linked %(#{link7_result} Link
), "#{link7_raw} Link
"
assert_linked %(Link #{link8_result}
), "Link #{link8_raw}
"
assert_linked %(#{link8_result} Link
), "#{link8_raw} Link
"
assert_linked %(Go to #{link8_result}.), %(Go to #{link8_raw}.)
assert_linked %(Go to #{link8_result}. seriously, #{link8_result}? i think I'll say hello to #{email_result}. instead.
), %(Go to #{link8_raw}. seriously, #{link8_raw}? i think I'll say hello to #{email_raw}. instead.
)
assert_linked %(Link #{link9_result}
), "Link #{link9_raw}
"
assert_linked %(#{link9_result} Link
), "#{link9_raw} Link
"
assert_linked %(Go to #{link9_result}.), %(Go to #{link9_raw}.)
assert_linked %(Go to #{link9_result}. seriously, #{link9_result}? i think I'll say hello to #{email_result}. instead.
), %(Go to #{link9_raw}. seriously, #{link9_raw}? i think I'll say hello to #{email_raw}. instead.
)
assert_linked %(#{link10_result} Link
), "#{link10_raw} Link
"
assert_linked email2_result, email2_raw
assert_linked "#{link_result} #{link_result} #{link_result}", "#{link_raw} #{link_raw} #{link_raw}"
assert_linked 'Ruby On Rails', 'Ruby On Rails'
end
def test_copies_source_encoding
str = "http://www.bash.org"
ret = Rinku.auto_link str
assert_equal str.encoding, ret.encoding
str.encode! 'binary'
ret = Rinku.auto_link str
assert_equal str.encoding, ret.encoding
end
def test_valid_encodings_are_generated
str = "<a href='http://gi.co'>gi.co</a>\xC2\xA0r"
assert_equal Encoding::UTF_8, str.encoding
res = Rinku.auto_link(str)
assert_equal Encoding::UTF_8, res.encoding
assert res.valid_encoding?
end
def test_polish_wikipedia_haha
url = "https://pl.wikipedia.org/wiki/Komisja_śledcza_do_zbadania_sprawy_zarzutu_nielegalnego_wywierania_wpływu_na_funkcjonariuszy_policji,_służb_specjalnych,_prokuratorów_i_osoby_pełniące_funkcje_w_organach_wymiaru_sprawiedliwości"
input = "A wikipedia link (#{url})"
expected = "A wikipedia link (#{url})"
assert_linked expected, input
end
def test_only_valid_encodings_are_accepted
str = "this is invalid \xA0 utf8"
assert_equal Encoding::UTF_8, str.encoding
assert !str.valid_encoding?
assert_raises ArgumentError do
Rinku.auto_link(str)
end
end
NBSP = "\xC2\xA0".freeze
def test_the_famous_nbsp
input = "at http://google.com/#{NBSP};"
expected = "at http://google.com/#{NBSP};"
assert_linked expected, input
end
def test_does_not_include_trailing_nonbreaking_spaces
url = "http://example.com/"
assert_linked "#{url}#{NBSP}and", "#{url}#{NBSP}and"
end
def test_identifies_preceeding_nonbreaking_spaces
url = "http://example.com/"
assert_linked "#{NBSP}#{url} and", "#{NBSP}#{url} and"
end
def test_urls_with_2_wide_UTF8_characters
url = "http://example.com/?foo=¥&bar=1"
assert_linked "#{url} and", "#{url} and"
end
def test_urls_with_4_wide_UTF8_characters
url = "http://example.com/?foo=&bar=1"
assert_linked "#{url} and", "#{url} and"
end
def test_handles_urls_with_emoji_properly
url = "http://foo.com/💖a"
assert_linked "#{url} and", "#{url} and"
end
def test_identifies_nonbreaking_spaces_preceeding_emails
email_raw = 'david@loudthinking.com'
assert_linked "email#{NBSP}#{email_raw}", "email#{NBSP}#{email_raw}"
end
def test_identifies_unicode_spaces
assert_linked(
%{This is just a test. http://www.pokemon.com\u202F\u2028\u2001},
"This is just a test. http://www.pokemon.com\u202F\u2028\u2001"
)
end
def test_www_is_case_insensitive
url = "www.reddit.com"
assert_linked generate_result(url), url
url = "WWW.REDDIT.COM"
assert_linked generate_result(url), url
url = "Www.reddit.Com"
assert_linked generate_result(url), url
url = "WwW.reddit.CoM"
assert_linked generate_result(url), url
end
def test_non_emails_ending_in_periods
assert_linked "abc/def@ghi.", "abc/def@ghi."
assert_linked "abc/def@ghi. ", "abc/def@ghi. "
assert_linked "abc/def@ghi. x", "abc/def@ghi. x"
assert_linked "abc/def@ghi.< x", "abc/def@ghi.< x"
assert_linked "abc/def@ghi.x", "abc/def@ghi.x"
assert_linked "abc/def@ghi.x. a", "abc/def@ghi.x. a"
end
def test_urls_with_entities_and_parens
assert_linked "<http://www.google.com>", "<http://www.google.com>"
assert_linked "<http://www.google.com>)", "<http://www.google.com>)"
# this produces invalid output, but limits how much work we will do
assert_linked "<http://www.google.com>)<)<)<)<)<)<)", "<http://www.google.com>)<)<)<)<)<)<)"
url = "http://pokemon.com/bulbasaur"
assert_linked "URL is #{generate_result(url)}.", "URL is #{url}."
assert_linked "(URL is #{generate_result(url)}.)", "(URL is #{url}.)"
url = "www.pokemon.com/bulbasaur"
assert_linked "URL is #{generate_result(url)}.", "URL is #{url}."
assert_linked "(URL is #{generate_result(url)}.)", "(URL is #{url}.)"
url = "abc@xyz.com"
assert_linked "URL is #{generate_result(url, "mailto:#{url}")}.", "URL is #{url}."
assert_linked "(URL is #{generate_result(url, "mailto:#{url}")}.)", "(URL is #{url}.)"
end
def test_urls_with_parens
assert_linked "(http://example.com)", "(http://example.com)"
assert_linked "((http://example.com/()))", "((http://example.com/()))"
assert_linked "[http://example.com/()]", "[http://example.com/()]"
assert_linked "(http://example.com/)", "(http://example.com/)"
assert_linked "【http://example.com/】", "【http://example.com/】"
assert_linked "『http://example.com/』", "『http://example.com/』"
assert_linked "「http://example.com/」", "「http://example.com/」"
assert_linked "《http://example.com/》", "《http://example.com/》"
assert_linked "〈http://example.com/〉", "〈http://example.com/〉"
end
def test_urls_with_quotes
assert_linked "'http://example.com'", "'http://example.com'"
assert_linked "\"http://example.com\"\"", "\"http://example.com\"\""
end
def test_underscore_in_domain
assert_linked "http://foo_bar.com", "http://foo_bar.com"
end
def test_underscore_in_subdomain
assert_linked "http://foo_bar.xyz.com", "http://foo_bar.xyz.com"
end
def test_regression_84
assert_linked "https://www.keepright.atの情報をもとにエラー修正", "https://www.keepright.atの情報をもとにエラー修正"
end
end