Created
September 11, 2008 14:02
-
-
Save NZKoz/10227 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
From 233020a2d01e9c4f0bfdd54657062312d2039a57 Mon Sep 17 00:00:00 2001 | |
From: Michael Koziarski <[email protected]> | |
Date: Thu, 11 Sep 2008 16:03:38 +0200 | |
Subject: [PATCH] Flesh out the parameterize method to support non-ascii text and underscores. | |
--- | |
activesupport/lib/active_support/inflector.rb | 2 +- | |
activesupport/test/inflector_test_cases.rb | 5 ++++- | |
2 files changed, 5 insertions(+), 2 deletions(-) | |
diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb | |
index e5f0063..8a917a9 100644 | |
--- a/activesupport/lib/active_support/inflector.rb | |
+++ b/activesupport/lib/active_support/inflector.rb | |
@@ -257,7 +257,7 @@ module ActiveSupport | |
# <%= link_to(@person.name, person_path %> | |
# # => <a href="/person/1-donald-e-knuth">Donald E. Knuth</a> | |
def parameterize(string, sep = '-') | |
- string.gsub(/[^a-z0-9]+/i, sep).downcase | |
+ string.chars.normalize(:kd).to_s.gsub(/[^\x00-\x7F]+/, '').gsub(/[^a-z0-9_\-]+/i, sep).downcase | |
end | |
# Create the name of a table like Rails does for models to table names. This method | |
diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb | |
index d399c90..8057809 100644 | |
--- a/activesupport/test/inflector_test_cases.rb | |
+++ b/activesupport/test/inflector_test_cases.rb | |
@@ -144,7 +144,10 @@ module InflectorTestCases | |
StringToParameterized = { | |
"Donald E. Knuth" => "donald-e-knuth", | |
- "Random text with *(bad)* characters" => "random-text-with-bad-characters" | |
+ "Random text with *(bad)* characters" => "random-text-with-bad-characters", | |
+ "Malmö" => "malmo", | |
+ "Garçons" => "garcons", | |
+ "Allow_Under_Scores" => "allow_under_scores" | |
} | |
UnderscoreToHuman = { | |
-- | |
1.6.0.1 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment