invalid_utf8_rejector 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3a17f73dd60c6ba59fa575894284aef13a3ca1eb
4
+ data.tar.gz: 6ce15f5f73ed3819194f63075f3daf32dcb91e98
5
+ SHA512:
6
+ metadata.gz: 3845821becaa77b57e7cae3e40742166eb8d8064d60eebe33ffe27dfc5ff695f1f4d467625ab1084e9d72fce4ab24c63b93a41e1cbbcd2e182530bf11ca5ca44
7
+ data.tar.gz: df226c3dba393f1f09a66231e059fd29c7f0e07bad1ff7f4584f2618fd07c2d833c019a2218d6768d0b330db22c9991df71f154f29fe2566391d19ebd587f7b2
data/.rspec CHANGED
@@ -1,2 +1,2 @@
1
1
  --color
2
- --format progress
2
+ --require spec_helper
data/.travis.yml CHANGED
@@ -1,3 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - "1.9.3"
4
+ - "2.1"
5
+ - "2.2"
data/LICENCE.txt CHANGED
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
21
  OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -10,7 +10,8 @@ Gem::Specification.new do |spec|
10
10
  spec.email = ["alex@tomlins.org.uk"]
11
11
  spec.description = %q{rack middleware to reject invalid UTF8 in requests. It will return a 400 if the decoded path or query string contain invalid UTF-8 chars.}
12
12
  spec.summary = %q{rack middleware to reject invalid UTF8 in requests}
13
- spec.homepage = ""
13
+ spec.homepage = "https://github.com/alext/invalid_utf8_rejector"
14
+ spec.license = "MIT"
14
15
 
15
16
  spec.files = `git ls-files`.split($/)
16
17
  spec.executables = spec.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
@@ -22,5 +23,5 @@ Gem::Specification.new do |spec|
22
23
  spec.add_development_dependency "bundler"
23
24
  spec.add_development_dependency "rake"
24
25
  spec.add_development_dependency "rack-test", "0.6.2"
25
- spec.add_development_dependency "rspec", "2.14.1"
26
+ spec.add_development_dependency "rspec", "~> 3.2"
26
27
  end
@@ -1,4 +1,4 @@
1
- require 'cgi'
1
+ require 'uri'
2
2
 
3
3
  module InvalidUTF8Rejector
4
4
  class Middleware
@@ -21,7 +21,10 @@ module InvalidUTF8Rejector
21
21
  end
22
22
 
23
23
  def clean_utf8?(str)
24
- CGI.unescape(str).force_encoding('UTF-8').valid_encoding?
24
+ return true if str.nil?
25
+ URI.decode_www_form_component(str).force_encoding('UTF-8').valid_encoding?
26
+ rescue ArgumentError # triggered by an invalid % encoded string.
27
+ false
25
28
  end
26
29
  end
27
30
  end
@@ -1,3 +1,3 @@
1
1
  module InvalidUTF8Rejector
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,9 +1,8 @@
1
- require 'spec_helper'
2
1
  require 'rack/test'
3
2
 
4
3
  require 'invalid_utf8_rejector'
5
4
 
6
- describe InvalidUTF8Rejector::Middleware do
5
+ RSpec.describe InvalidUTF8Rejector::Middleware do
7
6
  include Rack::Test::Methods
8
7
 
9
8
  def app
@@ -13,39 +12,69 @@ describe InvalidUTF8Rejector::Middleware do
13
12
  before :each do
14
13
  @inner_app_called = false
15
14
  end
16
-
15
+
17
16
  it "should pass a valid request to the inner app" do
18
17
  get "/foo?bar=baz"
19
18
  expect(last_response.status).to eq(200)
20
19
  expect(last_response.body).to match(/Inner app response/)
21
- expect(@inner_app_called).to be_true
20
+ expect(@inner_app_called).to eq(true)
22
21
  end
23
22
 
24
- it "should reject invalid UTF-8 chars in the path without calling the app" do
25
- get "/foo%A0bar"
26
- expect(last_response.status).to eq(400)
27
- expect(@inner_app_called).to be_false
28
- end
23
+ describe "handling invalid UTF-8 in requests" do
24
+
25
+ it "should reject invalid UTF-8 chars in the path without calling the app" do
26
+ get "/foo%A0bar"
27
+ expect(last_response.status).to eq(400)
28
+ expect(@inner_app_called).to eq(false)
29
+ end
29
30
 
30
- it "should reject malformed UTF-8 chars in the path without calling the app" do
31
- get "/br54ba%9CAQ%C4%FD%928owse"
32
- expect(last_response.status).to eq(400)
33
- expect(@inner_app_called).to be_false
31
+ it "should reject malformed UTF-8 chars in the path without calling the app" do
32
+ get "/br54ba%9CAQ%C4%FD%928owse"
33
+ expect(last_response.status).to eq(400)
34
+ expect(@inner_app_called).to eq(false)
35
+ end
36
+
37
+ it "should reject invalid UTF-8 chars in the query_string without calling the app" do
38
+ # Set params to nil. Without this, it defaults to empty hash, and rack-test tries to merge this with
39
+ # the given params which blows up with an invalid UTF-8 error before reaching our code
40
+ get "/foo?ba%a0r", nil
41
+ expect(last_response.status).to eq(400)
42
+ expect(@inner_app_called).to eq(false)
43
+ end
44
+
45
+ it "should reject malformed UTF-8 chars in the query_string without calling the app" do
46
+ # Set params to nil. Without this, it defaults to empty hash, and rack-test tries to merge this with
47
+ # the given params which blows up with an invalid UTF-8 error before reaching our code
48
+ get "/foo?bar=br54ba%9CAQ%C4%FD%928owse", nil
49
+ expect(last_response.status).to eq(400)
50
+ expect(@inner_app_called).to eq(false)
51
+ end
34
52
  end
35
53
 
36
- it "should reject invalid UTF-8 chars in the query_string without calling the app" do
37
- # Set params to nil. Without this, it defaults to empty hash, and rack-test tries to merge this with
38
- # the given params which blows up with an invalid UTF-8 error before reaching our code
39
- get "/foo?ba%a0r", nil
40
- expect(last_response.status).to eq(400)
41
- expect(@inner_app_called).to be_false
54
+ describe "handling invalid % encoded requests" do
55
+ it "should reject invalid % encoding in the path without calling the app" do
56
+ status, headers, body = raw_rack_get('/foo%+bar')
57
+ expect(status).to eq(400)
58
+ expect(@inner_app_called).to eq(false)
59
+ end
60
+
61
+ it "should reject invalid % encoding in the query_string without calling the app" do
62
+ status, headers, body = raw_rack_get('/foo', 'bar%=baz')
63
+ expect(status).to eq(400)
64
+ expect(@inner_app_called).to eq(false)
65
+ end
42
66
  end
43
67
 
44
- it "should reject malformed UTF-8 chars in the query_string without calling the app" do
45
- # Set params to nil. Without this, it defaults to empty hash, and rack-test tries to merge this with
46
- # the given params which blows up with an invalid UTF-8 error before reaching our code
47
- get "/foo?bar=br54ba%9CAQ%C4%FD%928owse", nil
48
- expect(last_response.status).to eq(400)
49
- expect(@inner_app_called).to be_false
68
+ # helper to bypass rack-test which errors when attempting to parse the invalid URLs
69
+ def raw_rack_get(path, query = nil)
70
+ env = {
71
+ 'REQUEST_METHOD' => 'GET',
72
+ 'SCRIPT_NAME' => '',
73
+ 'PATH_INFO' => path,
74
+ 'QUERY_STRING' => query,
75
+ 'SERVER_NAME' => 'example.org',
76
+ 'SERVER_PORT' => 80,
77
+ }
78
+ status, headers, body = app.call(env)
50
79
  end
51
80
  end
data/spec/spec_helper.rb CHANGED
@@ -1,17 +1,87 @@
1
1
  # This file was generated by the `rspec --init` command. Conventionally, all
2
2
  # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
- # Require this file using `require "spec_helper"` to ensure that it is only
4
- # loaded once.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
5
17
  #
6
18
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
7
19
  RSpec.configure do |config|
8
- config.treat_symbols_as_metadata_keys_with_true_values = true
9
- config.run_all_when_everything_filtered = true
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # These two settings work together to allow you to limit a spec run
44
+ # to individual examples or groups you care about by tagging them with
45
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
46
+ # get run.
10
47
  config.filter_run :focus
48
+ config.run_all_when_everything_filtered = true
49
+
50
+ # Limits the available syntax to the non-monkey patched syntax that is
51
+ # recommended. For more details, see:
52
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
53
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
54
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
55
+ config.disable_monkey_patching!
56
+
57
+ # This setting enables warnings. It's recommended, but in some cases may
58
+ # be too noisy due to issues in dependencies.
59
+ config.warnings = true
60
+
61
+ # Many RSpec users commonly either run the entire suite or an individual
62
+ # file, and it's useful to allow more verbose output when running an
63
+ # individual spec file.
64
+ if config.files_to_run.one?
65
+ # Use the documentation formatter for detailed output,
66
+ # unless a formatter has already been configured
67
+ # (e.g. via a command-line flag).
68
+ config.default_formatter = 'doc'
69
+ end
70
+
71
+ # Print the 10 slowest examples and example groups at the
72
+ # end of the spec run, to help surface which specs are running
73
+ # particularly slow.
74
+ #config.profile_examples = 10
11
75
 
12
76
  # Run specs in random order to surface order dependencies. If you find an
13
77
  # order dependency and want to debug it, you can fix the order by providing
14
78
  # the seed, which is printed after each run.
15
79
  # --seed 1234
16
- config.order = 'random'
80
+ config.order = :random
81
+
82
+ # Seed global randomization in this process using the `--seed` CLI option.
83
+ # Setting this allows you to use `--seed` to deterministically reproduce
84
+ # test failures related to randomization by passing the same `--seed` value
85
+ # as the one that triggered the failure.
86
+ Kernel.srand config.seed
17
87
  end
metadata CHANGED
@@ -1,68 +1,60 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invalid_utf8_rejector
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
5
- prerelease:
4
+ version: 0.0.2
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alex Tomlins
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-11-13 00:00:00.000000000 Z
11
+ date: 2015-03-13 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: rack
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ~>
17
+ - - "~>"
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ~>
24
+ - - "~>"
28
25
  - !ruby/object:Gem::Version
29
26
  version: '1.0'
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: bundler
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - ">="
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - ">="
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: rake
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - ">="
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - ">="
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  - !ruby/object:Gem::Dependency
63
56
  name: rack-test
64
57
  requirement: !ruby/object:Gem::Requirement
65
- none: false
66
58
  requirements:
67
59
  - - '='
68
60
  - !ruby/object:Gem::Version
@@ -70,7 +62,6 @@ dependencies:
70
62
  type: :development
71
63
  prerelease: false
72
64
  version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
65
  requirements:
75
66
  - - '='
76
67
  - !ruby/object:Gem::Version
@@ -78,19 +69,17 @@ dependencies:
78
69
  - !ruby/object:Gem::Dependency
79
70
  name: rspec
80
71
  requirement: !ruby/object:Gem::Requirement
81
- none: false
82
72
  requirements:
83
- - - '='
73
+ - - "~>"
84
74
  - !ruby/object:Gem::Version
85
- version: 2.14.1
75
+ version: '3.2'
86
76
  type: :development
87
77
  prerelease: false
88
78
  version_requirements: !ruby/object:Gem::Requirement
89
- none: false
90
79
  requirements:
91
- - - '='
80
+ - - "~>"
92
81
  - !ruby/object:Gem::Version
93
- version: 2.14.1
82
+ version: '3.2'
94
83
  description: rack middleware to reject invalid UTF8 in requests. It will return a
95
84
  400 if the decoded path or query string contain invalid UTF-8 chars.
96
85
  email:
@@ -99,9 +88,9 @@ executables: []
99
88
  extensions: []
100
89
  extra_rdoc_files: []
101
90
  files:
102
- - .gitignore
103
- - .rspec
104
- - .travis.yml
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
105
94
  - Gemfile
106
95
  - LICENCE.txt
107
96
  - README.md
@@ -113,35 +102,29 @@ files:
113
102
  - lib/invalid_utf8_rejector/version.rb
114
103
  - spec/middleware_spec.rb
115
104
  - spec/spec_helper.rb
116
- homepage: ''
117
- licenses: []
105
+ homepage: https://github.com/alext/invalid_utf8_rejector
106
+ licenses:
107
+ - MIT
108
+ metadata: {}
118
109
  post_install_message:
119
110
  rdoc_options: []
120
111
  require_paths:
121
112
  - lib
122
113
  required_ruby_version: !ruby/object:Gem::Requirement
123
- none: false
124
114
  requirements:
125
- - - ! '>='
115
+ - - ">="
126
116
  - !ruby/object:Gem::Version
127
117
  version: '0'
128
- segments:
129
- - 0
130
- hash: 4593929028848301
131
118
  required_rubygems_version: !ruby/object:Gem::Requirement
132
- none: false
133
119
  requirements:
134
- - - ! '>='
120
+ - - ">="
135
121
  - !ruby/object:Gem::Version
136
122
  version: '0'
137
- segments:
138
- - 0
139
- hash: 4593929028848301
140
123
  requirements: []
141
124
  rubyforge_project:
142
- rubygems_version: 1.8.23
125
+ rubygems_version: 2.2.2
143
126
  signing_key:
144
- specification_version: 3
127
+ specification_version: 4
145
128
  summary: rack middleware to reject invalid UTF8 in requests
146
129
  test_files:
147
130
  - spec/middleware_spec.rb