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 CHANGED
@@ -17,4 +17,6 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_runtime_dependency "sanitize", ">= 2.0.0"
19
19
  gem.add_runtime_dependency "sanitize-url", ">= 0.1.4"
20
+
21
+ gem.add_development_dependency "pry"
20
22
  end
data/lib/clean_room.rb CHANGED
@@ -1,8 +1,4 @@
1
- require "active_support"
2
-
3
1
  require "clean_room/air_lock"
4
2
  require "clean_room/dsl"
5
3
  require "clean_room/exceptions"
6
4
  require "clean_room/version"
7
-
8
- require "pry"
@@ -5,26 +5,51 @@ module CleanRoom
5
5
  class AirLock
6
6
  include SanitizeUrl
7
7
 
8
- def shower(value, options)
9
- if value
10
- allow = options[:allow] || :plain_text
8
+ def shower(dirty_value, options = {})
9
+ determine_and_clean(dirty_value, options)
10
+ end
11
11
 
12
- cleaned_value = case allow
13
- when :html
14
- Sanitize.clean(value, Sanitize::Config::RELAXED)
15
- when :simple_html
16
- Sanitize.clean(value, Sanitize::Config::BASIC)
17
- when :strict
18
- regex = /[^#{options[:character_class] || "a-zA-Z0-9 "}]/
19
- Sanitize.clean(value).gsub(regex, "")
20
- when :url
21
- sanitize_url(value)
22
- else
23
- Sanitize.clean(value)
24
- end
25
- else
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
@@ -1,3 +1,3 @@
1
1
  module CleanRoom
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
@@ -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.2
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: &70356218609500 !ruby/object:Gem::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: *70356218609500
24
+ version_requirements: *70175557841960
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: sanitize-url
27
- requirement: &70356218609000 !ruby/object:Gem::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: *70356218609000
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: