Sha256: a5ed9ae14bd844b6d054c082a89693e9de20f0a705b6abc04426f731f0f1a4c5

Contents?: true

Size: 877 Bytes

Versions: 11

Compression:

Stored size: 877 Bytes

Contents

require 'rack'

unless Rack::Utils.respond_to?(:uri_escape)
  module Rack
    module Utils
      def uri_escape(s)
        s.to_s.gsub(/([^:\/?\[\]\-_~\.!\$&'\(\)\*\+,;=@a-zA-Z0-9]+)/n) {
          '%'<<$1.unpack('H2'*$1.size).join('%').upcase
        }
      end
      module_function :uri_escape
    end
  end
end

unless Rack::Utils.respond_to?(:uri_escape!)
  module Rack
    module Utils
      def uri_escape!(s)
        s.to_s.gsub!(/([^:\/?\[\]\-_~\.!\$&'\(\)\*\+,;=@a-zA-Z0-9]+)/n) {
          '%'<<$1.unpack('H2'*$1.size).join('%').upcase
        }
      end
      module_function :uri_escape!
    end
  end
end

unless Rack::Utils.respond_to?(:uri_unescape)
  module Rack
    module Utils
      def uri_unescape(s)
        gsub(/((?:%[0-9a-fA-F]{2})+)/n){
          [$1.delete('%')].pack('H*')
        }
      end
      module_function :uri_unescape
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
usher-0.8.3 lib/usher/util/rack-mixins.rb
usher-0.8.2 lib/usher/util/rack-mixins.rb
usher-0.8.1 lib/usher/util/rack-mixins.rb
usher-0.8.0 lib/usher/util/rack-mixins.rb
usher-0.7.5 lib/usher/util/rack-mixins.rb
usher-0.7.4 lib/usher/util/rack-mixins.rb
usher-0.7.3 lib/usher/util/rack-mixins.rb
usher-0.7.2 lib/usher/util/rack-mixins.rb
usher-0.7.1 lib/usher/util/rack-mixins.rb
usher-0.7.0 lib/usher/util/rack-mixins.rb
usher-0.6.8 lib/usher/util/rack-mixins.rb