diff options
Diffstat (limited to 'activesupport/lib/active_support/core_ext')
4 files changed, 36 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/core_ext/array.rb b/activesupport/lib/active_support/core_ext/array.rb new file mode 100644 index 0000000000..83eef79b38 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/array.rb @@ -0,0 +1,5 @@ +require File.dirname(__FILE__) + '/array/to_param' + +class Array #:nodoc: + include ActiveSupport::CoreExtensions::Array::ToParam +end diff --git a/activesupport/lib/active_support/core_ext/array/to_param.rb b/activesupport/lib/active_support/core_ext/array/to_param.rb new file mode 100644 index 0000000000..85e91e6b1a --- /dev/null +++ b/activesupport/lib/active_support/core_ext/array/to_param.rb @@ -0,0 +1,12 @@ +module ActiveSupport #:nodoc: + module CoreExtensions #:nodoc: + module Array #:nodoc: + module ToParam #:nodoc: + # When an array is given to url_for, it is converted to a slash separated string. + def to_param + join '/' + end + end + end + end +end diff --git a/activesupport/lib/active_support/core_ext/cgi.rb b/activesupport/lib/active_support/core_ext/cgi.rb new file mode 100644 index 0000000000..2378297b7d --- /dev/null +++ b/activesupport/lib/active_support/core_ext/cgi.rb @@ -0,0 +1,5 @@ +require File.dirname(__FILE__) + '/cgi/escape_skipping_slashes' + +class CGI + extend(ActiveSupport::CoreExtensions::CGI::EscapeSkippingSlashes) +end 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 new file mode 100644 index 0000000000..a21e98fa80 --- /dev/null +++ b/activesupport/lib/active_support/core_ext/cgi/escape_skipping_slashes.rb @@ -0,0 +1,14 @@ +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(' ', '+') + end + end + end + end +end |