rack-indifferent 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4dc197e706d48727ac52eefbba3f0ce795e123ca
4
- data.tar.gz: b485a599d9fef549149db6aa1bd845d4d26d58a0
3
+ metadata.gz: 6eeac559ad3836d054b7c541846f37b298de8300
4
+ data.tar.gz: 34845a381540a1a33357e3c1d7519214139e1234
5
5
  SHA512:
6
- metadata.gz: 85e5b41de703623d69b7a3d10aafda2443f37278e99547e82cbb6f5e71fa6602b47491c7b418f5ae52ac9abca57f901b3a1ef1f74f4cb9060fbdab0819d5892d
7
- data.tar.gz: 8c2da5241b89361057cb043d682004c59fe1431e89da79e676cebc146fed86184db2a7f52eec8dbec4450e9a76cddb648181df162bd2e6414dea089f00df55f5
6
+ metadata.gz: 69602aadf87abb0056624104297d87b37bc5af159043445d27e30065c02da8de73f22a387961996e35ed0873c2c32500b5659b7104b5079770a3f447150dcfda
7
+ data.tar.gz: dee47d84bd98c6fdffb0ea349b51f58319bcc60c310c321a1ee75fb901eb9027bd476c18f4183ea7c84a40c3deead264f284c0693d58572a99a4913ab3924847
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ = 1.2.0 (2016-09-20)
2
+
3
+ * Work correctly with rack 2 when empty GET parameters are used (jeremyevans)
4
+
1
5
  = 1.1.0 (2015-03-08)
2
6
 
3
7
  * Reduce the number of procs created (jeremyevans)
@@ -1,4 +1,4 @@
1
- Copyright (c) 2015 Jeremy Evans
1
+ Copyright (c) 2015-2016 Jeremy Evans
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -1,9 +1,9 @@
1
1
  = rack-indifferent
2
2
 
3
- rack-indifferent monkey patches Rack::Utils::KeySpaceConstrainedParams
4
- to make the hash it stores params in support indifferent access. So web
5
- frameworks that use rack-indifferent don't have to make a deep copy
6
- of the params to allow indifferent access to the params.
3
+ rack-indifferent modifiesrack to make the hash it stores query params in
4
+ support indifferent access. This allows web frameworks/applications that
5
+ use rack-indifferent don't have to make a deep copy of the params to allow
6
+ indifferent access to the params.
7
7
 
8
8
  == Installation
9
9
 
@@ -15,12 +15,17 @@ Source code is available on GitHub at https://github.com/jeremyevans/rack-indiff
15
15
 
16
16
  == Basic Usage
17
17
 
18
- Since this just monkey patches part of Rack::Utils, you just need to require
19
- the library:
18
+ You just need to require the library:
20
19
 
21
20
  require 'rack/indifferent'
22
21
 
23
- This will change the params hashes that rack uses to use indifferent access.
22
+ On rack 1, this will monkey patch a rack class to change the query params hashes
23
+ that rack uses to use indifferent access.
24
+
25
+ On rack 2, this will set a new default query parser that uses hashes with
26
+ indifferent access. Note that web frameworks and applications that use
27
+ custom query parsers in their request class will not be affected by
28
+ rack-indifferent.
24
29
 
25
30
  == License
26
31
 
data/Rakefile CHANGED
@@ -8,34 +8,8 @@ task :package=>[:clean] do |p|
8
8
  sh %{#{FileUtils::RUBY} -S gem build rack-indifferent.gemspec}
9
9
  end
10
10
 
11
- ### Specs
12
-
13
- begin
14
- begin
15
- # RSpec 1
16
- require "spec/rake/spectask"
17
- spec_class = Spec::Rake::SpecTask
18
- spec_files_meth = :spec_files=
19
- rescue LoadError
20
- # RSpec 2
21
- require "rspec/core/rake_task"
22
- spec_class = RSpec::Core::RakeTask
23
- spec_files_meth = :pattern=
24
- end
25
-
26
- spec = lambda do |name, files, d|
27
- lib_dir = File.join(File.dirname(File.expand_path(__FILE__)), 'lib')
28
- ENV['RUBYLIB'] ? (ENV['RUBYLIB'] += ":#{lib_dir}") : (ENV['RUBYLIB'] = lib_dir)
29
- desc d
30
- spec_class.new(name) do |t|
31
- t.send(spec_files_meth, files)
32
- end
33
- end
34
-
35
- task :default => [:spec]
36
- spec.call("spec", Dir["spec/*_spec.rb"], "Run specs")
37
- rescue LoadError
38
- task :default do
39
- puts "Must install rspec to run the default task (which runs specs)"
40
- end
11
+ desc "Build rack-indifferent gem"
12
+ task :spec do |p|
13
+ sh %{#{FileUtils::RUBY} -rubygems -I lib spec/indifferent_spec.rb}
41
14
  end
15
+ task :default => :spec
@@ -1,12 +1,36 @@
1
+ require 'rack'
1
2
  require 'rack/utils'
2
3
 
3
- class Rack::Utils::KeySpaceConstrainedParams
4
- INDIFFERENT_PROC = lambda{|h,k| h[k.to_s] if k.is_a?(Symbol)}
4
+ if Rack.release > '2'
5
+ module Rack::Indifferent
6
+ class QueryParser < Rack::QueryParser
7
+ # Work around for invalid optimization in rack
8
+ def parse_nested_query(qs, d=nil)
9
+ return make_params.to_params_hash if qs.nil? || qs.empty?
10
+ super
11
+ end
12
+
13
+ class Params < Rack::QueryParser::Params
14
+ INDIFFERENT_PROC = lambda{|h,k| h[k.to_s] if k.is_a?(Symbol)}
5
15
 
6
- def initialize(limit = Rack::Utils.key_space_limit)
7
- @limit = limit
8
- @size = 0
9
- @params = Hash.new(&INDIFFERENT_PROC)
16
+ def initialize(limit = Rack::Utils.key_space_limit)
17
+ @limit = limit
18
+ @size = 0
19
+ @params = Hash.new(&INDIFFERENT_PROC)
20
+ end
21
+ end
22
+
23
+ Rack::Utils.default_query_parser = new(Params, 65536, 100)
24
+ end
10
25
  end
11
- end
26
+ else
27
+ class Rack::Utils::KeySpaceConstrainedParams
28
+ INDIFFERENT_PROC = lambda{|h,k| h[k.to_s] if k.is_a?(Symbol)}
12
29
 
30
+ def initialize(limit = Rack::Utils.key_space_limit)
31
+ @limit = limit
32
+ @size = 0
33
+ @params = Hash.new(&INDIFFERENT_PROC)
34
+ end
35
+ end
36
+ end
@@ -1,25 +1,23 @@
1
1
  require File.join(File.dirname(File.expand_path(__FILE__)), '../lib/rack/indifferent')
2
2
  require 'rack/mock'
3
-
4
- if defined?(RSpec)
5
- require 'rspec/version'
6
- if RSpec::Version::STRING >= '2.11.0'
7
- RSpec.configure do |config|
8
- config.expect_with :rspec do |c|
9
- c.syntax = :should
10
- end
11
- end
12
- end
13
- end
3
+ require 'minitest/autorun'
14
4
 
15
5
  describe 'rack-indifferent' do
16
6
  it "should make requests use indifferent param hashes" do
17
7
  params = Rack::Request.new(Rack::MockRequest.env_for('/?a=b&c[d]=e&f[][g]=h', :input=>'i=j&k[l]=m&n[][o]=p', :method=>'POST')).params
18
- params[:a].should == 'b'
19
- params[:c][:d].should == 'e'
20
- params[:f][0][:g].should == 'h'
21
- params[:i].should == 'j'
22
- params[:k][:l].should == 'm'
23
- params[:n][0][:o].should == 'p'
8
+ params[:a].must_equal 'b'
9
+ params[:c][:d].must_equal 'e'
10
+ params[:f][0][:g].must_equal 'h'
11
+ params[:i].must_equal 'j'
12
+ params[:k][:l].must_equal 'm'
13
+ params[:n][0][:o].must_equal 'p'
14
+ end
15
+
16
+ it "should make requests handle empty params" do
17
+ params = Rack::Request.new(Rack::MockRequest.env_for('/', :input=>'i=j&k[l]=m&n[][o]=p', :method=>'POST')).params
18
+ params[:a].must_equal nil
19
+ params[:i].must_equal 'j'
20
+ params[:k][:l].must_equal 'm'
21
+ params[:n][0][:o].must_equal 'p'
24
22
  end
25
23
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-indifferent
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Evans
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-09 00:00:00.000000000 Z
11
+ date: 2016-09-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  version: '0'
75
75
  requirements: []
76
76
  rubyforge_project:
77
- rubygems_version: 2.4.5
77
+ rubygems_version: 2.5.1
78
78
  signing_key:
79
79
  specification_version: 4
80
80
  summary: Fast indifferent access to request params