activecleaner 0.2.0 โ 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -1
- data/lib/active_cleaner.rb +1 -0
- data/lib/active_cleaner/utf8mb3_cleaner.rb +13 -0
- data/lib/active_cleaner/version.rb +1 -1
- data/spec/cases/inherit_spec.rb +24 -3
- data/spec/cases/nilify_spec.rb +24 -3
- data/spec/cases/simple_spec.rb +24 -3
- data/spec/lib/active_cleaner/utf8mb4_cleaner_spec.rb +29 -0
- metadata +10 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f568e263b920da28be6897d33c390ba37d100d02
|
4
|
+
data.tar.gz: 6649a5b52ece6e7181a8c3d8bc635c3e671dd5d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 09c356b188281b08dd78d2c9d99622234c0be6d2be3f795a9dce25c7e27c527f3e5880cf60f4f125bad8f648e319658aeab9d810c47cf7e7b97f1467122e3cc0
|
7
|
+
data.tar.gz: 26fcaef9a2105e5df417ec0a8c1440d56b1792acfac489bbd2606fdc1464333dcbb83296cf6f4084abcc61398920cd0cb10244f7a308d4ddfcd1b5187810bc5a
|
data/README.md
CHANGED
@@ -1,6 +1,8 @@
|
|
1
1
|
# ActiveCleaner
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/activecleaner.svg)](
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/activecleaner.svg)](https://rubygems.org/gems/activecleaner)
|
4
|
+
[![Build Status](https://travis-ci.org/maximeg/activecleaner.svg?branch=master)](https://travis-ci.org/maximeg/activecleaner)
|
5
|
+
[![Dependency Status](https://gemnasium.com/maximeg/activecleaner.svg)](https://gemnasium.com/maximeg/activecleaner)
|
4
6
|
|
5
7
|
`ActiveCleaner` is a set of helpers that helps you in cleaning user-typed content in your ActiveModel depending models (ActiveRecord, Mongoid...)
|
6
8
|
|
@@ -26,6 +28,7 @@ end
|
|
26
28
|
* `:string` (StringCleaner, the default one) : cleans all the space characters. It turns `" A \n \t title \t "` into `"A title"`.
|
27
29
|
* `:text` (TextCleaner) : like `:string`, but preserves new lines (with a max of 2 successive new lines). useful when the field is rendered with the `simple_format` Rails helper.
|
28
30
|
* `:markdown` (MarkdownCleaner) : like `:text`, but preserves spaces in the beginning of lines (the indentation). useful for... markdown!
|
31
|
+
* `:utf8mb3` (Utf8mb3Cleaner) : removes all 4-bytes encoded chars in UTF8 strings that mess with the `utf8` encoding in MySQL (iOS6 emojis for example).
|
29
32
|
|
30
33
|
|
31
34
|
|
data/lib/active_cleaner.rb
CHANGED
data/spec/cases/inherit_spec.rb
CHANGED
@@ -17,9 +17,10 @@ class Ad
|
|
17
17
|
end
|
18
18
|
|
19
19
|
class CarAd < Ad
|
20
|
-
attr_accessor :body
|
20
|
+
attr_accessor :body, :user_generated_content
|
21
21
|
|
22
22
|
clean :body, as: :text
|
23
|
+
clean :user_generated_content, as: :utf8mb3
|
23
24
|
end
|
24
25
|
|
25
26
|
#
|
@@ -49,8 +50,8 @@ describe "Case: an ad and his inherited car ad" do
|
|
49
50
|
|
50
51
|
subject { CarAd._cleaners }
|
51
52
|
|
52
|
-
it "has
|
53
|
-
expect(subject.length).to eq(
|
53
|
+
it "has 4 cleaners" do
|
54
|
+
expect(subject.length).to eq(4)
|
54
55
|
end
|
55
56
|
|
56
57
|
it "includes a StringCleaner for #title" do
|
@@ -65,6 +66,10 @@ describe "Case: an ad and his inherited car ad" do
|
|
65
66
|
expect(subject[:body].first).to eq(ActiveCleaner::TextCleaner.new(:body))
|
66
67
|
end
|
67
68
|
|
69
|
+
it "includes a Utf8mb3Cleaner for #user_generated_content" do
|
70
|
+
expect(subject[:user_generated_content].first).to eq(ActiveCleaner::Utf8mb3Cleaner.new(:user_generated_content))
|
71
|
+
end
|
72
|
+
|
68
73
|
end # describe
|
69
74
|
|
70
75
|
context "considering a car ad" do
|
@@ -119,6 +124,22 @@ describe "Case: an ad and his inherited car ad" do
|
|
119
124
|
|
120
125
|
end # describe
|
121
126
|
|
127
|
+
describe "#user_generated_content, marked as to clean as utf8mb3" do
|
128
|
+
|
129
|
+
it "is untouched when legit" do
|
130
|
+
subject.user_generated_content = "A good user generated content!"
|
131
|
+
subject.valid?
|
132
|
+
expect(subject.user_generated_content).to eq("A good user generated content!")
|
133
|
+
end
|
134
|
+
|
135
|
+
it "is cleaned as an utf8mb3" do
|
136
|
+
subject.user_generated_content = "A good ๐ user generated content!"
|
137
|
+
subject.valid?
|
138
|
+
expect(subject.user_generated_content).to eq("A good user generated content!")
|
139
|
+
end
|
140
|
+
|
141
|
+
end # describe
|
142
|
+
|
122
143
|
end # context
|
123
144
|
|
124
145
|
end # describe
|
data/spec/cases/nilify_spec.rb
CHANGED
@@ -9,11 +9,12 @@ require "spec_helper"
|
|
9
9
|
class OptimizedPost
|
10
10
|
include ActiveCleaner
|
11
11
|
|
12
|
-
attr_accessor :title, :name, :body
|
12
|
+
attr_accessor :title, :name, :body, :user_generated_content
|
13
13
|
|
14
14
|
clean :title, nilify: true
|
15
15
|
clean :name, as: :string, nilify: true
|
16
16
|
clean :body, as: :text, nilify: true
|
17
|
+
clean :user_generated_content, as: :utf8mb3, nilify: true
|
17
18
|
end
|
18
19
|
|
19
20
|
|
@@ -26,8 +27,8 @@ describe "Case: a simple post with nulify" do
|
|
26
27
|
|
27
28
|
subject { OptimizedPost._cleaners }
|
28
29
|
|
29
|
-
it "has
|
30
|
-
expect(subject.length).to eq(
|
30
|
+
it "has 4 cleaners" do
|
31
|
+
expect(subject.length).to eq(4)
|
31
32
|
end
|
32
33
|
|
33
34
|
it "includes a StringCleaner for #title" do
|
@@ -42,6 +43,10 @@ describe "Case: a simple post with nulify" do
|
|
42
43
|
expect(subject[:body].first).to eq(ActiveCleaner::TextCleaner.new(:body, nilify: true))
|
43
44
|
end
|
44
45
|
|
46
|
+
it "includes a Utf8mb3Cleaner for #user_generated_content" do
|
47
|
+
expect(subject[:user_generated_content].first).to eq(ActiveCleaner::Utf8mb3Cleaner.new(:user_generated_content, nilify: true))
|
48
|
+
end
|
49
|
+
|
45
50
|
end # describe
|
46
51
|
|
47
52
|
context "considering a post" do
|
@@ -96,6 +101,22 @@ describe "Case: a simple post with nulify" do
|
|
96
101
|
|
97
102
|
end # describe
|
98
103
|
|
104
|
+
describe "#user_generated_content, marked as to clean as utf8mb3" do
|
105
|
+
|
106
|
+
it "is untouched when legit" do
|
107
|
+
subject.user_generated_content = "A good user generated content!"
|
108
|
+
subject.valid?
|
109
|
+
expect(subject.user_generated_content).to eq("A good user generated content!")
|
110
|
+
end
|
111
|
+
|
112
|
+
it "is nulified" do
|
113
|
+
subject.user_generated_content = "๐"
|
114
|
+
subject.valid?
|
115
|
+
expect(subject.user_generated_content).to be_nil
|
116
|
+
end
|
117
|
+
|
118
|
+
end # describe
|
119
|
+
|
99
120
|
end # context
|
100
121
|
|
101
122
|
end # describe
|
data/spec/cases/simple_spec.rb
CHANGED
@@ -9,11 +9,12 @@ require "spec_helper"
|
|
9
9
|
class Post
|
10
10
|
include ActiveCleaner
|
11
11
|
|
12
|
-
attr_accessor :title, :name, :body
|
12
|
+
attr_accessor :title, :name, :body, :user_generated_content
|
13
13
|
|
14
14
|
clean :title
|
15
15
|
clean :name, as: :string
|
16
16
|
clean :body, as: :text
|
17
|
+
clean :user_generated_content, as: :utf8mb3
|
17
18
|
end
|
18
19
|
|
19
20
|
|
@@ -26,8 +27,8 @@ describe "Case: a simple post" do
|
|
26
27
|
|
27
28
|
subject { Post._cleaners }
|
28
29
|
|
29
|
-
it "has
|
30
|
-
expect(subject.length).to eq(
|
30
|
+
it "has 4 cleaners" do
|
31
|
+
expect(subject.length).to eq(4)
|
31
32
|
end
|
32
33
|
|
33
34
|
it "includes a StringCleaner for #title" do
|
@@ -42,6 +43,10 @@ describe "Case: a simple post" do
|
|
42
43
|
expect(subject[:body].first).to eq(ActiveCleaner::TextCleaner.new(:body))
|
43
44
|
end
|
44
45
|
|
46
|
+
it "includes a Utf8mb3Cleaner for #user_generated_content" do
|
47
|
+
expect(subject[:user_generated_content].first).to eq(ActiveCleaner::Utf8mb3Cleaner.new(:user_generated_content))
|
48
|
+
end
|
49
|
+
|
45
50
|
end # describe
|
46
51
|
|
47
52
|
context "considering a post" do
|
@@ -96,6 +101,22 @@ describe "Case: a simple post" do
|
|
96
101
|
|
97
102
|
end # describe
|
98
103
|
|
104
|
+
describe "#user_generated_content, marked as to clean as utf8mb3" do
|
105
|
+
|
106
|
+
it "is untouched when legit" do
|
107
|
+
subject.user_generated_content = "A good user generated content!"
|
108
|
+
subject.valid?
|
109
|
+
expect(subject.user_generated_content).to eq("A good user generated content!")
|
110
|
+
end
|
111
|
+
|
112
|
+
it "is cleaned as an utf8mb3" do
|
113
|
+
subject.user_generated_content = "A good ๐ user generated content!"
|
114
|
+
subject.valid?
|
115
|
+
expect(subject.user_generated_content).to eq("A good user generated content!")
|
116
|
+
end
|
117
|
+
|
118
|
+
end # describe
|
119
|
+
|
99
120
|
end # context
|
100
121
|
|
101
122
|
end # describe
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
describe ActiveCleaner::Utf8mb3Cleaner do
|
5
|
+
|
6
|
+
let(:cleaner) { ActiveCleaner::Utf8mb3Cleaner.new(:title) }
|
7
|
+
|
8
|
+
describe "#clean_value" do
|
9
|
+
|
10
|
+
it "doesn't touch legit value" do
|
11
|
+
expect(cleaner.clean_value("A good title!")).to eq("A good title!")
|
12
|
+
end
|
13
|
+
|
14
|
+
it "cleans emoticons" do
|
15
|
+
emoticons = "๐๐๐๐๐๐
๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐๐ ๐ก๐ข๐ฃ๐ค๐ฅ๐ฆ๐ง๐จ๐ฉ๐ช๐ซ๐ฌ๐ญ๐ฎ๐ฏ๐ฐ๐ฑ๐ฒ๐ณ๐ด๐ต๐ถ๐ท๐ธ๐น๐บ๐ป๐ผ๐ฝ๐พ๐ฟ๐๐๐๐
๐๐๐๐๐๐๐๐๐๐"
|
16
|
+
expect(cleaner.clean_value("A good #{emoticons} title!")).to eq("A good title!")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "kepts accentued chars" do
|
20
|
+
expect(cleaner.clean_value("L'Inouรฏ Goรปter ร Manger.")).to eq("L'Inouรฏ Goรปter ร Manger.")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "kepts japanese chars" do
|
24
|
+
expect(cleaner.clean_value("ginkล is written as ้่ก")).to eq("ginkล is written as ้่ก")
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activecleaner
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Maxime Garcia
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-12-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -86,6 +86,7 @@ files:
|
|
86
86
|
- lib/active_cleaner/markdown_cleaner.rb
|
87
87
|
- lib/active_cleaner/string_cleaner.rb
|
88
88
|
- lib/active_cleaner/text_cleaner.rb
|
89
|
+
- lib/active_cleaner/utf8mb3_cleaner.rb
|
89
90
|
- lib/active_cleaner/version.rb
|
90
91
|
- lib/activecleaner.rb
|
91
92
|
- spec/cases/inherit_spec.rb
|
@@ -94,6 +95,7 @@ files:
|
|
94
95
|
- spec/lib/active_cleaner/markdown_cleaner_spec.rb
|
95
96
|
- spec/lib/active_cleaner/string_cleaner_spec.rb
|
96
97
|
- spec/lib/active_cleaner/text_cleaner_spec.rb
|
98
|
+
- spec/lib/active_cleaner/utf8mb4_cleaner_spec.rb
|
97
99
|
- spec/lib/active_cleaner_spec.rb
|
98
100
|
- spec/spec_helper.rb
|
99
101
|
homepage: http://github.com/maximeg/activecleaner
|
@@ -116,16 +118,17 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
116
118
|
version: 1.3.6
|
117
119
|
requirements: []
|
118
120
|
rubyforge_project:
|
119
|
-
rubygems_version: 2.4.
|
121
|
+
rubygems_version: 2.4.2
|
120
122
|
signing_key:
|
121
123
|
specification_version: 4
|
122
124
|
summary: Clean the fields in your models
|
123
125
|
test_files:
|
124
|
-
- spec/
|
126
|
+
- spec/cases/simple_spec.rb
|
127
|
+
- spec/cases/inherit_spec.rb
|
128
|
+
- spec/cases/nilify_spec.rb
|
125
129
|
- spec/lib/active_cleaner/text_cleaner_spec.rb
|
130
|
+
- spec/lib/active_cleaner/utf8mb4_cleaner_spec.rb
|
131
|
+
- spec/lib/active_cleaner/string_cleaner_spec.rb
|
126
132
|
- spec/lib/active_cleaner/markdown_cleaner_spec.rb
|
127
133
|
- spec/lib/active_cleaner_spec.rb
|
128
134
|
- spec/spec_helper.rb
|
129
|
-
- spec/cases/inherit_spec.rb
|
130
|
-
- spec/cases/simple_spec.rb
|
131
|
-
- spec/cases/nilify_spec.rb
|