Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Use gsub method on String instead of SafeBuffer. Fix for incompatibil…

…ity with Rails 3.1.0.rc2.
  • Loading branch information...
commit 68daf9efbb6a7ebfa16a0f6967c9360d1664fa18 1 parent fe9d2c7
Juanjo Bazán xuanxu authored
Showing with 13 additions and 4 deletions.
  1. +13 −4 lib/rails_autolink.rb
17 lib/rails_autolink.rb
View
@@ -60,11 +60,12 @@ def auto_link(text, *args, &block)#link = :all, html = {}, &block)
options[:html] = args[1] || {}
end
options.reverse_merge!(:link => :all, :html => {})
- text = sanitize(text) unless options[:sanitize] == false
+ sanitize = (options[:sanitize] != false)
+ text = conditional_sanitize(text, sanitize).to_str
case options[:link].to_sym
- when :all then auto_link_email_addresses(auto_link_urls(text, options[:html], options, &block), options[:html], &block)
- when :email_addresses then auto_link_email_addresses(text, options[:html], &block)
- when :urls then auto_link_urls(text, options[:html], options, &block)
+ when :all then conditional_html_safe(auto_link_email_addresses(auto_link_urls(text, options[:html], options, &block), options[:html], &block), sanitize)
+ when :email_addresses then conditional_html_safe(auto_link_email_addresses(text, options[:html], &block), sanitize)
+ when :urls then conditional_html_safe(auto_link_urls(text, options[:html], options, &block), sanitize)
end
end
@@ -140,6 +141,14 @@ def auto_linked?(left, right)
(left =~ AUTO_LINK_CRE[0] and right =~ AUTO_LINK_CRE[1]) or
(left.rindex(AUTO_LINK_CRE[2]) and $' !~ AUTO_LINK_CRE[3])
end
+
+ def conditional_sanitize(target, condition)
+ condition ? sanitize(target) : target
+ end
+
+ def conditional_html_safe(target, condition)
+ condition ? target.html_safe : target
+ end
end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.