utf8_attribute_sanitiser 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +9 -1
- data/lib/utf8_attribute_sanitiser.rb +6 -2
- data/lib/utf8_attribute_sanitiser/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cbb7d85533242790e75e8f9e43895bf387de33ab
|
4
|
+
data.tar.gz: 54c1ea7a00a4484421aa15a70e4aab27cb9afe23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 932b99e00cbd3efd7623202b5d37a46abb4331ca898be055f4ea57099cee8051650beaab4ebcb038973f5b3ed83d2bbc50b9fa97efbfd45d3196bb6b3c6d9edb
|
7
|
+
data.tar.gz: af36edb47e5ff513201b4d0598071d0d1dd2cb8ae845e259490718e6d04048cc7c87988f5df7cdcef5bf6dda9228ef7185bce1c469a3286031798cd76a7e6099
|
data/README.md
CHANGED
@@ -26,13 +26,21 @@ In your model add utf8_attribute_sanitiser, specyfing list of attribute names to
|
|
26
26
|
utf8_attribute_sanitiser :name, :address
|
27
27
|
end
|
28
28
|
|
29
|
+
Default cleaning method is `utf8mb4only` and it only affects 4 byte characters
|
30
|
+
|
31
|
+
You can use aggressive clean method that strips out all invalud utf8 characters like
|
32
|
+
|
33
|
+
class User < ActiveRecord::Base
|
34
|
+
utf8_attribute_sanitiser :name, :address, method: :aggressive
|
35
|
+
end
|
36
|
+
|
29
37
|
## Running tests
|
30
38
|
|
31
39
|
$ rspec
|
32
40
|
|
33
41
|
## Contributing
|
34
42
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
43
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/tomdracz/utf8_attribute_sanitiser.
|
36
44
|
|
37
45
|
|
38
46
|
## License
|
@@ -1,11 +1,15 @@
|
|
1
1
|
require "utf8_attribute_sanitiser/version"
|
2
2
|
|
3
3
|
module Utf8AttributeSanitiser
|
4
|
-
def utf8_attribute_sanitiser(*attributes)
|
4
|
+
def utf8_attribute_sanitiser(*attributes, method: :utf8mb4only)
|
5
5
|
attributes.each do |attribute|
|
6
6
|
before_validation do |record|
|
7
7
|
value = record[attribute]
|
8
|
-
|
8
|
+
if method == :utf8mb4only
|
9
|
+
sanitised_value = value.respond_to?(:encode) ? value.each_char.select{|c| c.bytes.count < 4 }.join('') : value
|
10
|
+
elsif method == :aggressive
|
11
|
+
sanitised_value = value.respond_to?(:gsub) ? value.encode('UTF-8', 'binary', invalid: :replace, undef: :replace, replace: "") : value
|
12
|
+
end
|
9
13
|
record[attribute] = sanitised_value
|
10
14
|
end
|
11
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: utf8_attribute_sanitiser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Dracz
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-07-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -90,7 +90,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
90
|
version: '0'
|
91
91
|
requirements: []
|
92
92
|
rubyforge_project:
|
93
|
-
rubygems_version: 2.6.
|
93
|
+
rubygems_version: 2.6.10
|
94
94
|
signing_key:
|
95
95
|
specification_version: 4
|
96
96
|
summary: Sanitise attributes to avoid invalid byte sequence argument errors
|