string_scrubber 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/README.md +59 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/circle.yml +6 -0
- data/lib/string_scrubber/version.rb +3 -0
- data/lib/string_scrubber.rb +11 -0
- data/string_scrubber.gemspec +34 -0
- metadata +142 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d69a96381b06bf1557646ec2d66e41258d9fd9d0
|
4
|
+
data.tar.gz: 53e798dbf0153e94f621c8cbf78bf4cd59cbb42e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 0959fc9b1982c70654295c3d5b803062f31f8a3c2d3882ea8ffe1915e84b8b6ba0be312ca11275459bf8e8d1c34be4247b155ec3b2df9e7c40c858930f49ee43
|
7
|
+
data.tar.gz: 3ee73fd5bf22105b928aa38d571ada8bccc9af397824c0a64a484057b8fd31837dd0c4d17f5c3e709e5bbbb13419b16ff02ec2abe9dd83425694aec259c3c01d
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/README.md
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# StringScrubber
|
2
|
+
|
3
|
+
[![Code
|
4
|
+
Climate](https://codeclimate.com/github/ministryofjustice/string_scrubber/badges/gpa.svg)](https://codeclimate.com/github/ministryofjustice/string_scrubber)
|
5
|
+
[![Circle
|
6
|
+
CI](https://circleci.com/gh/ministryofjustice/string_scrubber.svg?style=svg)](https://circleci.com/gh/ministryofjustice/string_scrubber)
|
7
|
+
[![Test
|
8
|
+
Coverage](https://codeclimate.com/github/ministryofjustice/string_scrubber/badges/coverage.svg)](https://codeclimate.com/github/ministryofjustice/string_scrubber/coverage)
|
9
|
+
|
10
|
+
|
11
|
+
This gem prevents #to_json calls from raising exceptions on strings that
|
12
|
+
are not UTF-8 encoded. It was written to deal with logging failures in the
|
13
|
+
[logstasher](https://github.com/shadabahmed/logstasher) gem.
|
14
|
+
|
15
|
+
The exceptions were `JSON::GeneratorError` and
|
16
|
+
`Encoding::UndefinedConversionError` and occurred when trying to log
|
17
|
+
controller parameters that contained ASCII-8BIT strings. You can
|
18
|
+
reproduce these errors on a running app using the following `curl`
|
19
|
+
command:
|
20
|
+
|
21
|
+
```bash
|
22
|
+
curl -i -X GET "http://localhost:3000/tests" -d $'param=a\xE2a'
|
23
|
+
```
|
24
|
+
|
25
|
+
See the specs for a typical example string.
|
26
|
+
|
27
|
+
## Installation
|
28
|
+
|
29
|
+
Add this line to your application's Gemfile:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
gem 'MoJ_IRAT_string_scrubber'
|
33
|
+
```
|
34
|
+
|
35
|
+
And then execute:
|
36
|
+
|
37
|
+
$ bundle
|
38
|
+
|
39
|
+
Or install it yourself as:
|
40
|
+
|
41
|
+
$ gem install MoJ_IRAT_string_scrubber
|
42
|
+
|
43
|
+
## Usage
|
44
|
+
|
45
|
+
Install it. It does the rest.
|
46
|
+
|
47
|
+
## Development
|
48
|
+
|
49
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake rspec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
50
|
+
|
51
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
52
|
+
|
53
|
+
## Contributing
|
54
|
+
|
55
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/MoJ_IRAT_string_scrubber.
|
56
|
+
|
57
|
+
## License
|
58
|
+
|
59
|
+
[Open Government License v3.0](https://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/)
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "string_scrubber"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
data/circle.yml
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'string_scrubber/version'
|
2
|
+
|
3
|
+
module StringScrubber
|
4
|
+
def to_json(options = nil)
|
5
|
+
self.force_encoding('UTF-8') unless self.encoding == Encoding::UTF_8
|
6
|
+
self.scrub! unless self.valid_encoding?
|
7
|
+
super(options)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
String.prepend(StringScrubber)
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'string_scrubber/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "string_scrubber"
|
8
|
+
spec.version = StringScrubber::VERSION
|
9
|
+
spec.authors = ["Todd Tyree"]
|
10
|
+
spec.email = ["todd.tyree@digital.justice.gov.uk"]
|
11
|
+
|
12
|
+
spec.summary = %q{Drop in fix for JSON UTF-8 encoding errors in logstasher.}
|
13
|
+
spec.description = %q{Logstasher fails if controller params are not properly encoded. This fixes these.}
|
14
|
+
spec.homepage = "http://github.com/ministryofjustice/string_scrubber"
|
15
|
+
spec.license = 'ogl'
|
16
|
+
|
17
|
+
if spec.respond_to?(:metadata)
|
18
|
+
spec.metadata['allowed_push_host'] = 'https://rubygems.org'
|
19
|
+
else
|
20
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
21
|
+
end
|
22
|
+
|
23
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
spec.bindir = "exe"
|
25
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
26
|
+
spec.require_paths = ["lib"]
|
27
|
+
|
28
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
29
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
30
|
+
spec.add_development_dependency "rspec", "~> 3.3"
|
31
|
+
spec.add_development_dependency "json", "~> 1.8"
|
32
|
+
spec.add_development_dependency "simplecov", "~> 0.10"
|
33
|
+
spec.add_development_dependency "codeclimate-test-reporter", "~> 0.4"
|
34
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: string_scrubber
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Todd Tyree
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-08-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.10'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.10'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '3.3'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: json
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.8'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.8'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: simplecov
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.10'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.10'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: codeclimate-test-reporter
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0.4'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0.4'
|
97
|
+
description: Logstasher fails if controller params are not properly encoded. This
|
98
|
+
fixes these.
|
99
|
+
email:
|
100
|
+
- todd.tyree@digital.justice.gov.uk
|
101
|
+
executables: []
|
102
|
+
extensions: []
|
103
|
+
extra_rdoc_files: []
|
104
|
+
files:
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
108
|
+
- Gemfile
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- bin/console
|
112
|
+
- bin/setup
|
113
|
+
- circle.yml
|
114
|
+
- lib/string_scrubber.rb
|
115
|
+
- lib/string_scrubber/version.rb
|
116
|
+
- string_scrubber.gemspec
|
117
|
+
homepage: http://github.com/ministryofjustice/string_scrubber
|
118
|
+
licenses:
|
119
|
+
- ogl
|
120
|
+
metadata:
|
121
|
+
allowed_push_host: https://rubygems.org
|
122
|
+
post_install_message:
|
123
|
+
rdoc_options: []
|
124
|
+
require_paths:
|
125
|
+
- lib
|
126
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
127
|
+
requirements:
|
128
|
+
- - ">="
|
129
|
+
- !ruby/object:Gem::Version
|
130
|
+
version: '0'
|
131
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
requirements: []
|
137
|
+
rubyforge_project:
|
138
|
+
rubygems_version: 2.4.5
|
139
|
+
signing_key:
|
140
|
+
specification_version: 4
|
141
|
+
summary: Drop in fix for JSON UTF-8 encoding errors in logstasher.
|
142
|
+
test_files: []
|