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 +4 -4
- data/.travis.yml +2 -0
- data/README.md +1 -0
- data/lib/utf8-cleaner/middleware.rb +10 -1
- data/lib/utf8-cleaner/version.rb +1 -1
- data/spec/middleware_spec.rb +11 -2
- data/spec/uri_string_spec.rb +1 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3430532196f27d692b381b983f9379c09e64daeb
|
4
|
+
data.tar.gz: 0245109f3fa9f3c6c36beefacf5180f5799f1f46
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b2e43c9c6b904c0ae23eb06f12a392c544adef9712ea017aa75e2d0b200680f5e7e154acd7d9d65c3859d2e252a39f6458f4dcd6fb42e4a5ab4e8b4d8337d89e
|
7
|
+
data.tar.gz: 440f660f1e62a99e0387e8991a63605776ce7ad8e0182404aebc3cf54ea44830aa0a7c78b75bdbc143b57458237e6e5c5c19ff2d31b2fc83e00d5de897bd8a6d
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -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'
|
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
|
data/lib/utf8-cleaner/version.rb
CHANGED
data/spec/middleware_spec.rb
CHANGED
@@ -61,9 +61,18 @@ module UTF8Cleaner
|
|
61
61
|
before do
|
62
62
|
env['CONTENT_TYPE'] = 'application/json'
|
63
63
|
end
|
64
|
-
|
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(
|
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
|
data/spec/uri_string_spec.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2016-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|