Module: URI::Escape

Defined in:
lib/babushka/core_patches/uri.rb

Instance Method Summary collapse

Instance Method Details

#escape(str, unsafe = URI::UNSAFE) ⇒ Object

Patch URI.escape to prevent multiple escapes, by unescaping the input before escaping it.

For example, URI.escape normally behaves like this:

URI.escape "path with spaces"      #=> "path%20with%20spaces"
URI.escape "/path%20with%20spaces" #=> "/path%2520with%2520spaces"

This patched version behaves like this:

URI.escape "/path with spaces"     #=> "/path%20with%20spaces"
URI.escape "/path%20with%20spaces" #=> "/path%20with%20spaces"

This is pretty cheeky, but as far as I can see it won’t cause any problems - I can’t see any situation where a doubly-escaped entity is a good thing.



20
21
22
# File 'lib/babushka/core_patches/uri.rb', line 20

def escape str, unsafe = URI::UNSAFE
  URI.original_escape URI.unescape(str), unsafe
end

#original_escapeObject



4
# File 'lib/babushka/core_patches/uri.rb', line 4

alias_method :original_escape, :escape