clean_room 0.1.2 → 0.1.3
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.
- data/clean_room.gemspec +2 -0
- data/lib/clean_room.rb +0 -4
- data/lib/clean_room/air_lock.rb +43 -18
- data/lib/clean_room/version.rb +1 -1
- data/test/clean_room_test.rb +8 -0
- metadata +16 -5
data/clean_room.gemspec
CHANGED
data/lib/clean_room.rb
CHANGED
data/lib/clean_room/air_lock.rb
CHANGED
@@ -5,26 +5,51 @@ module CleanRoom
|
|
5
5
|
class AirLock
|
6
6
|
include SanitizeUrl
|
7
7
|
|
8
|
-
def shower(
|
9
|
-
|
10
|
-
|
8
|
+
def shower(dirty_value, options = {})
|
9
|
+
determine_and_clean(dirty_value, options)
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
12
|
+
def determine_and_clean(dirty_value, options)
|
13
|
+
|
14
|
+
case dirty_value
|
15
|
+
when Array
|
16
|
+
dirty_value.map{ |dv| determine_and_clean(dv, options) }
|
17
|
+
when Hash
|
18
|
+
Hash[dirty_value.map {|k,dv| [determine_and_clean(k, allow: (k.is_a?(Symbol) ? :symbol : :string)),determine_and_clean(dv, options)]}]
|
19
|
+
when Fixnum
|
20
|
+
dirty_value
|
21
|
+
when Symbol
|
22
|
+
clean(dirty_value, options).to_sym
|
23
|
+
when FalseClass
|
24
|
+
false
|
25
|
+
when NilClass
|
26
26
|
nil
|
27
|
+
else
|
28
|
+
clean(dirty_value, options)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def clean(dirty_value, options)
|
33
|
+
dirty_value = dirty_value.to_s
|
34
|
+
case (options[:allow] || :plain_text)
|
35
|
+
when :html
|
36
|
+
Sanitize.clean(dirty_value, Sanitize::Config::RELAXED)
|
37
|
+
when :simple_html
|
38
|
+
Sanitize.clean(dirty_value, Sanitize::Config::BASIC)
|
39
|
+
when :strict
|
40
|
+
regex = /[^#{options[:character_class] || "a-zA-Z0-9 "}]/
|
41
|
+
Sanitize.clean(dirty_value).gsub(regex, "")
|
42
|
+
when :url
|
43
|
+
sanitize_url(dirty_value)
|
44
|
+
when :symbol
|
45
|
+
Sanitize.clean(dirty_value).gsub(/[^a-zA-Z0-9]/, "").to_sym
|
46
|
+
when :fixnum
|
47
|
+
Sanitize.clean(dirty_value).gsub(/[^0-9]\.\,/, "").gsub(",",".").to_i
|
48
|
+
when :float
|
49
|
+
Sanitize.clean(dirty_value).gsub(/[^0-9\.\,]/, "").gsub(",",".").to_f
|
50
|
+
else
|
51
|
+
Sanitize.clean(dirty_value)
|
27
52
|
end
|
28
|
-
end
|
53
|
+
end
|
29
54
|
end
|
30
55
|
end
|
data/lib/clean_room/version.rb
CHANGED
data/test/clean_room_test.rb
CHANGED
@@ -33,6 +33,14 @@ class CleanRoomTest < MiniTest::Unit::TestCase
|
|
33
33
|
attribute_test(:url, "www.google.com/?q=<script>test</script>", "http://www.google.com/?q=%3Cscript%3Etest%3C/script%3E")
|
34
34
|
end
|
35
35
|
|
36
|
+
def test_air_lock
|
37
|
+
assert_equal ["test1","test2"], CleanRoom::AirLock.new.shower(["<b>test1</b>","<b>test2</b>"])
|
38
|
+
assert_equal [{"test1" => "test3"},"test2"], CleanRoom::AirLock.new.shower([{"<b>test1</b>" => "<b>test3</b>"},"<b>test2</b>"])
|
39
|
+
assert_equal [{test1: "test3"},"test2"], CleanRoom::AirLock.new.shower([{:"<b>te * st1</b>" => "<b>test3</b>"},"<b>test2</b>"])
|
40
|
+
assert_equal ["123.", "456.3", "789.8"], CleanRoom::AirLock.new.shower(["<b>123.</b>","456.3", 789.8])
|
41
|
+
assert_equal [123, 456, 789], CleanRoom::AirLock.new.shower(["<b>123.</b>","456.3", 789.8], allow: :fixnum)
|
42
|
+
assert_equal [123.0, 456.3, 789.8], CleanRoom::AirLock.new.shower(["<b>123.</b>","456.3", 789.8], allow: :float)
|
43
|
+
end
|
36
44
|
|
37
45
|
def attribute_test(field, value_in, value_out)
|
38
46
|
object = object_generator
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clean_room
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-06-19 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sanitize
|
16
|
-
requirement: &
|
16
|
+
requirement: &70175557841960 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.0.0
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70175557841960
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: sanitize-url
|
27
|
-
requirement: &
|
27
|
+
requirement: &70175557841420 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,18 @@ dependencies:
|
|
32
32
|
version: 0.1.4
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70175557841420
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: pry
|
38
|
+
requirement: &70175557841000 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70175557841000
|
36
47
|
description: Work in progress, this will be a generic attribute sanitizer which can
|
37
48
|
be used for sanitizing models and other objects holding data
|
38
49
|
email:
|