aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/inflector.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/inflector.rb')
-rw-r--r--activesupport/lib/active_support/inflector.rb14
1 files changed, 8 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb
index 4921b99677..3ed30bdf56 100644
--- a/activesupport/lib/active_support/inflector.rb
+++ b/activesupport/lib/active_support/inflector.rb
@@ -257,15 +257,17 @@ module ActiveSupport
# <%= link_to(@person.name, person_path(@person)) %>
# # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a>
def parameterize(string, sep = '-')
- re_sep = Regexp.escape(sep)
# replace accented chars with ther ascii equivalents
parameterized_string = transliterate(string)
# Turn unwanted chars into the seperator
parameterized_string.gsub!(/[^a-z0-9\-_\+]+/i, sep)
- # No more than one of the separator in a row.
- parameterized_string.squeeze!(sep)
- # Remove leading/trailing separator.
- parameterized_string.gsub!(/^#{re_sep}|#{re_sep}$/i, '')
+ unless sep.blank?
+ re_sep = Regexp.escape(sep)
+ # No more than one of the separator in a row.
+ parameterized_string.gsub!(/#{re_sep}{2,}/, sep)
+ # Remove leading/trailing separator.
+ parameterized_string.gsub!(/^#{re_sep}|#{re_sep}$/i, '')
+ end
parameterized_string.downcase
end
@@ -284,7 +286,7 @@ module ActiveSupport
# The iconv transliteration code doesn't function correctly
# on some platforms, but it's very fast where it does function.
- elsif "foo" != Inflector.transliterate("föö")
+ elsif "foo" != (Inflector.transliterate("föö") rescue nil)
undef_method :transliterate
def transliterate(string)
string.mb_chars.normalize(:kd). # Decompose accented characters