utf8-cleaner 0.2.2 → 0.2.3

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: 483d7ad030797ac6e4f59b23989e85cb02f8c871
4
- data.tar.gz: ed06229b5cec24770bbfaba9c4586528a0f519a3
3
+ metadata.gz: 3430532196f27d692b381b983f9379c09e64daeb
4
+ data.tar.gz: 0245109f3fa9f3c6c36beefacf5180f5799f1f46
5
5
  SHA512:
6
- metadata.gz: 80b2ec52b93bf99814b479d1059db52f8a8c507ee8df0434c29cc644ba93a65100573c1e4a3609f97a0bd94170cdad23bee0926064dc2e52d9c2d429d88c2635
7
- data.tar.gz: 019d366a8de11b5c55625be6e4c19f3260d35d62e059b30111acc1cfc0c8fc5cd0c9c173e8003308a5fc6fc409305a6e3aaaa23066a172215cddb7f268238f62
6
+ metadata.gz: b2e43c9c6b904c0ae23eb06f12a392c544adef9712ea017aa75e2d0b200680f5e7e154acd7d9d65c3859d2e252a39f6458f4dcd6fb42e4a5ab4e8b4d8337d89e
7
+ data.tar.gz: 440f660f1e62a99e0387e8991a63605776ce7ad8e0182404aebc3cf54ea44830aa0a7c78b75bdbc143b57458237e6e5c5c19ff2d31b2fc83e00d5de897bd8a6d
data/.travis.yml CHANGED
@@ -1,3 +1,5 @@
1
+ before_install:
2
+ - gem install bundler
1
3
  language: ruby
2
4
  rvm:
3
5
  - 1.9.3
data/README.md CHANGED
@@ -43,3 +43,4 @@ Original middleware author: @phoet - https://gist.github.com/phoet/1336754
43
43
  * Ruby 1.9.3 compatibility: @pithyless - https://gist.github.com/pithyless/3639014
44
44
  * Code review and cleanup: @nextmat
45
45
  * POST body sanitization: @salrepe
46
+ * Bug fixes: @cosine
@@ -40,10 +40,19 @@ module UTF8Cleaner
40
40
 
41
41
  def sanitize_env_rack_input(env)
42
42
  case env['CONTENT_TYPE']
43
- when 'application/x-www-form-urlencoded','application/json'
43
+ when 'application/x-www-form-urlencoded'
44
+ # This data gets the full cleaning treatment
44
45
  cleaned_value = cleaned_string(env['rack.input'].read)
45
46
  env['rack.input'] = StringIO.new(cleaned_value) if cleaned_value
46
47
  env['rack.input'].rewind
48
+ when 'application/json'
49
+ # This data only gets cleaning of invalid UTF-8 (e.g. from another charset)
50
+ # but we do not URI-decode it.
51
+ rack_input = env['rack.input'].read
52
+ if rack_input && !rack_input.ascii_only?
53
+ env['rack.input'] = StringIO.new(tidy_bytes(rack_input))
54
+ end
55
+ env['rack.input'].rewind
47
56
  when 'multipart/form-data'
48
57
  # Don't process the data since it may contain binary content
49
58
  else
@@ -1,3 +1,3 @@
1
1
  module UTF8Cleaner
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
@@ -61,9 +61,18 @@ module UTF8Cleaner
61
61
  before do
62
62
  env['CONTENT_TYPE'] = 'application/json'
63
63
  end
64
- it "removes removes invalid %-encoded UTF-8 sequences" do
64
+
65
+ it "tidies invalid UTF-8 sequences" do
66
+ env['rack.input'] = StringIO.new(%Q({"foo": "\xFFbar\xF8"}))
65
67
  env['rack.input'].rewind
66
- expect(new_env['rack.input'].read).to eq('foo=bar')
68
+ expect(new_env['rack.input'].read).to eq(%Q({"foo": "\u00FFbar\u00F8"}))
69
+ end
70
+
71
+ it "does not attempt to URI-decode data" do
72
+ json = %Q({"foo": "%FF"})
73
+ env['rack.input'] = StringIO.new(json)
74
+ env['rack.input'].rewind
75
+ expect(new_env['rack.input'].read).to eq(json)
67
76
  end
68
77
  end
69
78
  end
@@ -1,3 +1,4 @@
1
+ # encoding: UTF-8
1
2
  require 'spec_helper'
2
3
 
3
4
  module UTF8Cleaner
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: utf8-cleaner
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leon Miller-Out
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-03-21 00:00:00.000000000 Z
11
+ date: 2016-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport