Sha256: 9cf7f3d8090173ae3dbc1b759a6e54b17150161874ad0e31921d26ee2ef9fbb3

Contents?: true

Size: 1021 Bytes

Versions: 24

Compression:

Stored size: 1021 Bytes

Contents

# frozen-string-literal: true

require 'rack/utils'

#
class Roda
  module RodaPlugins
    # The unescape_path plugin decodes a URL-encoded path
    # before routing.  This fixes routing when the slashes
    # are URL-encoded as %2f and returns decoded parameters
    # when matched by symbols or regexps.
    #
    #   plugin :unescape_path
    #
    #   route do |r|
    #     # Assume /b/a URL encoded at %2f%62%2f%61
    #     r.on :x, /(.)/ do |*x|
    #       # x => ['b', 'a']
    #     end
    #   end
    module UnescapePath
      module RequestMethods
        # Make sure the matched path calculation handles the unescaping
        # of the remaining path.
        def matched_path
          e = @env
          Rack::Utils.unescape(e["SCRIPT_NAME"] + e["PATH_INFO"]).chomp(@remaining_path)
        end

        private

        # Unescape the path.
        def _remaining_path(env)
          Rack::Utils.unescape(super)
        end
      end
    end

    register_plugin(:unescape_path, UnescapePath)
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
roda-3.86.0 lib/roda/plugins/unescape_path.rb
roda-3.85.0 lib/roda/plugins/unescape_path.rb
roda-3.84.0 lib/roda/plugins/unescape_path.rb
roda-3.83.0 lib/roda/plugins/unescape_path.rb
roda-3.82.0 lib/roda/plugins/unescape_path.rb
roda-3.81.0 lib/roda/plugins/unescape_path.rb
roda-3.79.0 lib/roda/plugins/unescape_path.rb
roda-3.78.0 lib/roda/plugins/unescape_path.rb
roda-3.77.0 lib/roda/plugins/unescape_path.rb
roda-3.76.0 lib/roda/plugins/unescape_path.rb
roda-3.75.0 lib/roda/plugins/unescape_path.rb
roda-3.74.0 lib/roda/plugins/unescape_path.rb
roda-3.73.0 lib/roda/plugins/unescape_path.rb
roda-3.72.0 lib/roda/plugins/unescape_path.rb
roda-3.71.0 lib/roda/plugins/unescape_path.rb
roda-3.70.0 lib/roda/plugins/unescape_path.rb
roda-3.69.0 lib/roda/plugins/unescape_path.rb
roda-3.68.0 lib/roda/plugins/unescape_path.rb
roda-3.67.0 lib/roda/plugins/unescape_path.rb
roda-3.66.0 lib/roda/plugins/unescape_path.rb