diff options
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb | 19 | ||||
-rw-r--r-- | activesupport/lib/active_support/inflector.rb | 9 | ||||
-rw-r--r-- | activesupport/lib/active_support/test_case.rb | 1 | ||||
-rw-r--r-- | activesupport/test/inflector_test.rb | 6 | ||||
-rw-r--r-- | activesupport/test/inflector_test_cases.rb | 15 |
5 files changed, 42 insertions, 8 deletions
diff --git a/activesupport/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb b/activesupport/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb index a21e98fa80..1edb3771a2 100644 --- a/activesupport/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb +++ b/activesupport/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb @@ -2,11 +2,20 @@ module ActiveSupport #:nodoc: module CoreExtensions #:nodoc: module CGI #:nodoc: module EscapeSkippingSlashes #:nodoc: - def escape_skipping_slashes(str) - str = str.join('/') if str.respond_to? :join - str.gsub(/([^ \/a-zA-Z0-9_.-])/n) do - "%#{$1.unpack('H2').first.upcase}" - end.tr(' ', '+') + if RUBY_VERSION >= '1.9' + def escape_skipping_slashes(str) + str = str.join('/') if str.respond_to? :join + str.gsub(/([^ \/a-zA-Z0-9_.-])/n) do + "%#{$1.unpack('H2' * $1.bytesize).join('%').upcase}" + end.tr(' ', '+') + end + else + def escape_skipping_slashes(str) + str = str.join('/') if str.respond_to? :join + str.gsub(/([^ \/a-zA-Z0-9_.-])/n) do + "%#{$1.unpack('H2').first.upcase}" + end.tr(' ', '+') + end end end end diff --git a/activesupport/lib/active_support/inflector.rb b/activesupport/lib/active_support/inflector.rb index ad2660e6c8..683af4556e 100644 --- a/activesupport/lib/active_support/inflector.rb +++ b/activesupport/lib/active_support/inflector.rb @@ -275,9 +275,16 @@ module ActiveSupport Iconv.iconv('ascii//ignore//translit', 'utf-8', string).to_s end + if RUBY_VERSION >= '1.9' + undef_method :transliterate + def transliterate(string) + warn "Ruby 1.9 doesn't support Unicode normalization yet" + string.dup + end + # The iconv transliteration code doesn't function correctly # on some platforms, but it's very fast where it does function. - if "foo" != Inflector.transliterate("föö") + elsif "foo" != Inflector.transliterate("föö") undef_method :transliterate def transliterate(string) string.mb_chars.normalize(:kd). # Decompose accented characters diff --git a/activesupport/lib/active_support/test_case.rb b/activesupport/lib/active_support/test_case.rb index 1cc8564a18..97b2b6ef9c 100644 --- a/activesupport/lib/active_support/test_case.rb +++ b/activesupport/lib/active_support/test_case.rb @@ -17,6 +17,7 @@ module ActiveSupport class TestCase < ::Test::Unit::TestCase if defined? MiniTest Assertion = MiniTest::Assertion + alias_method :method_name, :name else # TODO: Figure out how to get the Rails::BacktraceFilter into minitest/unit if defined?(Rails) diff --git a/activesupport/test/inflector_test.rb b/activesupport/test/inflector_test.rb index d30852c013..d8c93dc9ae 100644 --- a/activesupport/test/inflector_test.rb +++ b/activesupport/test/inflector_test.rb @@ -104,6 +104,12 @@ class InflectorTest < Test::Unit::TestCase end end + def test_parameterize_and_normalize + StringToParameterizedAndNormalized.each do |some_string, parameterized_string| + assert_equal(parameterized_string, ActiveSupport::Inflector.parameterize(some_string)) + end + end + def test_parameterize_with_custom_separator StringToParameterized.each do |some_string, parameterized_string| assert_equal(parameterized_string.gsub('-', '_'), ActiveSupport::Inflector.parameterize(some_string, '_')) diff --git a/activesupport/test/inflector_test_cases.rb b/activesupport/test/inflector_test_cases.rb index 3aa18ca781..481c3e835c 100644 --- a/activesupport/test/inflector_test_cases.rb +++ b/activesupport/test/inflector_test_cases.rb @@ -147,14 +147,25 @@ module InflectorTestCases StringToParameterized = { "Donald E. Knuth" => "donald-e-knuth", "Random text with *(bad)* characters" => "random-text-with-bad-characters", - "Malmö" => "malmo", - "Garçons" => "garcons", "Allow_Under_Scores" => "allow_under_scores", "Trailing bad characters!@#" => "trailing-bad-characters", "!@#Leading bad characters" => "leading-bad-characters", "Squeeze separators" => "squeeze-separators" } + # Ruby 1.9 doesn't do Unicode normalization yet. + if RUBY_VERSION >= '1.9' + StringToParameterizedAndNormalized = { + "Malmö" => "malm", + "Garçons" => "gar-ons" + } + else + StringToParameterizedAndNormalized = { + "Malmö" => "malmo", + "Garçons" => "garcons" + } + end + UnderscoreToHuman = { "employee_salary" => "Employee salary", "employee_id" => "Employee", |