Skip to content

Instantly share code, notes, and snippets.

@purcell
Created June 5, 2012 19:40
Show Gist options
  • Select an option

  • Save purcell/2877275 to your computer and use it in GitHub Desktop.

Select an option

Save purcell/2877275 to your computer and use it in GitHub Desktop.

Revisions

  1. purcell created this gist Jun 5, 2012.
    37 changes: 37 additions & 0 deletions rack_cookie_fix.rb
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    # Monkeypatch fix for https://github.com/rack/rack/issues/386 achieved by
    # applying https://github.com/rack/rack/commit/2dfe94071497678c15cfcd8e63663d92f82958e5

    raise "remove this fix" if Gem.loaded_specs["rack"].version > Gem::Version.new("1.4.1")

    module Rack
    module Utils
    def parse_query(qs, d = nil)
    params = KeySpaceConstrainedParams.new

    (qs || '').split(d ? /[#{d}] */n : DEFAULT_SEP).each do |p|
    k, v = p.split('=', 2).map { |x| unescape(x) }
    next unless k || v

    if cur = params[k]
    if cur.class == Array
    params[k] << v
    else
    params[k] = [cur, v]
    end
    else
    params[k] = v
    end
    end

    return params.to_params_hash
    end

    class KeySpaceConstrainedParams
    def []=(key, value)
    @size += key.size if key && !@params.key?(key)
    raise RangeError, 'exceeded available parameter key space' if @size > @limit
    @params[key] = value
    end
    end
    end
    end