Skip to content
Browse files

update PermalinkFu.escape to go with edge rails

  • Loading branch information...
1 parent 106c900 commit bdedce0286c89008023499781dabefc1978712f6 @technoweenie technoweenie committed
Showing with 8 additions and 7 deletions.
  1. +8 −7 lib/permalink_fu.rb
View
15 lib/permalink_fu.rb
@@ -11,13 +11,14 @@ class << self
attr_accessor :translation_from
# This method does the actual permalink escaping.
- def escape(str)
- s = ((translation_to && translation_from) ? Iconv.iconv(translation_to, translation_from, str) : str).to_s
- s.gsub!(/[^\w -]+/, '') # strip unwanted characters
- s.strip! # ohh la la
- s.downcase! #
- s.gsub!(/[ -]+/, '-') # separate by single dashes
- s
+ def escape(string)
+ result = ((translation_to && translation_from) ? Iconv.iconv(translation_to, translation_from, string) : string).to_s
+ result.gsub!(/[^\x00-\x7F]+/, '') # Remove anything non-ASCII entirely (e.g. diacritics).
+ result.gsub!(/[^\w_ \-]+/i, '') # Remove unwanted chars.
+ result.gsub!(/[ \-]+/i, '-') # No more than one of the separator in a row.
+ result.gsub!(/^\-|\-$/i, '') # Remove leading/trailing separator.
+ result.downcase!
+ result
end
end

0 comments on commit bdedce0

Please sign in to comment.
Something went wrong with that request. Please try again.