clean_room 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -26,14 +26,14 @@ CleanRoom accepts any attributes for which readers and writers are available. Th
26
26
  * html: allow the tags as by Sanitize::Config::RELAXED
27
27
 
28
28
 
29
- class SanitizedAttributes
30
- attr_accessor :normal, :strict, :very_strict, :simple_html, :html
31
-
32
- sanitize_attribute :normal
33
- sanitize_attribute :strict, allow: :strict, character_class: "a-z"
34
- sanitize_attribute :simple_html, allow: :simple_html
35
- sanitize_attribute :html, allow: :html
36
- end
29
+ class SanitizedAttributes
30
+ attr_accessor :normal, :strict, :very_strict, :simple_html, :html
31
+
32
+ sanitize_attribute :normal
33
+ sanitize_attribute :strict, allow: :strict, character_class: "a-z"
34
+ sanitize_attribute :simple_html, allow: :simple_html
35
+ sanitize_attribute :html, allow: :html
36
+ end
37
37
 
38
38
 
39
39
  ## Contributing
data/clean_room.gemspec CHANGED
@@ -13,9 +13,8 @@ Gem::Specification.new do |gem|
13
13
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
14
  gem.name = "clean_room"
15
15
  gem.require_paths = ["lib"]
16
+ gem.version = CleanRoom::VERSION
16
17
 
17
- gem.add_runtime_dependency "activesupport", ">= 3.0.0"
18
18
  gem.add_runtime_dependency "sanitize", ">= 2.0.0"
19
-
20
- gem.version = CleanRoom::VERSION
19
+ gem.add_runtime_dependency "sanitize-url", ">= 0.1.4"
21
20
  end
data/lib/clean_room.rb CHANGED
@@ -4,3 +4,5 @@ require "clean_room/air_lock"
4
4
  require "clean_room/dsl"
5
5
  require "clean_room/exceptions"
6
6
  require "clean_room/version"
7
+
8
+ require "pry"
@@ -1,7 +1,10 @@
1
1
  require 'sanitize'
2
+ require 'sanitize-url'
2
3
 
3
4
  module CleanRoom
4
5
  class AirLock
6
+ include SanitizeUrl
7
+
5
8
  def shower(value, options)
6
9
  if value
7
10
  allow = options[:allow] || :plain_text
@@ -14,6 +17,8 @@ module CleanRoom
14
17
  when :strict
15
18
  regex = /[^#{options[:character_class] || "a-zA-Z0-9 "}]/
16
19
  Sanitize.clean(value).gsub(regex, "")
20
+ when :url
21
+ sanitize_url(value)
17
22
  else
18
23
  Sanitize.clean(value)
19
24
  end
@@ -1,12 +1,12 @@
1
1
  module CleanRoom
2
2
  module DSL
3
- extend ActiveSupport::Concern
4
3
 
5
- included do
6
- self.sanitizable_attributes = {}
4
+ def self.included(base)
5
+ base.extend ClassMethods
6
+ base.sanitizable_attributes = {}
7
7
 
8
- if respond_to? :before_save
9
- before_save :sanitize_attributes
8
+ if base.respond_to? :before_save
9
+ base.before_save :sanitize_attributes
10
10
  end
11
11
  end
12
12
 
@@ -1,3 +1,3 @@
1
1
  module CleanRoom
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -30,30 +30,42 @@ class CleanRoomTest < MiniTest::Unit::TestCase
30
30
  attribute_test(:simple_html, "<b>Test-tesT</b>", "<b>Test-tesT</b>")
31
31
  attribute_test(:simple_html, "<b>Test-tesT</b><div>block</div><table><tr><td>table</td></tr></table>", "<b>Test-tesT</b> block table")
32
32
  attribute_test(:html, "<b>Test-tesT</b><div>block</div><table><tr><td>table</td></tr></table>", "<b>Test-tesT</b> block <table><tr><td>table</td></tr></table>")
33
+ attribute_test(:url, "www.google.com/?q=<script>test</script>", "http://www.google.com/?q=%3Cscript%3Etest%3C/script%3E")
33
34
  end
34
35
 
35
36
 
36
37
  def attribute_test(field, value_in, value_out)
37
- test_object.send("#{field}=".to_sym, value_in)
38
- test_object.sanitize_attributes
39
- assert_equal value_out, test_object.send(field)
38
+ object = object_generator
39
+ object.send("#{field}=".to_sym, value_in)
40
+ object.sanitize_attributes
41
+ assert_equal value_out, object.send(field)
40
42
  end
41
43
 
42
- def test_object
43
- unless @test_object
44
- test_class = Class.new do
45
- include CleanRoom::DSL
46
- attr_accessor :normal, :strict, :very_strict, :simple_html, :html
47
-
48
- sanitize_attribute :normal
49
- sanitize_attribute :strict, allow: :strict
50
- sanitize_attribute :very_strict, allow: :strict, character_class: "a-z"
51
- sanitize_attribute :simple_html, allow: :simple_html
52
- sanitize_attribute :html, allow: :html
53
- end
44
+ def object_generator
45
+ test_class = Class.new do
46
+ include CleanRoom::DSL
47
+ attr_accessor :normal, :strict, :very_strict, :simple_html, :html, :url
54
48
 
55
- @test_object = test_class.new
49
+ sanitize_attribute :normal
50
+ sanitize_attribute :strict, allow: :strict
51
+ sanitize_attribute :very_strict, allow: :strict, character_class: "a-z"
52
+ sanitize_attribute :simple_html, allow: :simple_html
53
+ sanitize_attribute :html, allow: :html
54
+ sanitize_attribute :url, allow: :url
56
55
  end
57
- @test_object
56
+
57
+ test_class.new
58
58
  end
59
+
60
+
61
+ def test_with_before_save
62
+ assert_output("sanitize_attributes\n") do
63
+ test_class = Class.new do
64
+ def self.before_save(method_name)
65
+ puts method_name
66
+ end
67
+ include CleanRoom::DSL
68
+ end
69
+ end
70
+ end
59
71
  end
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.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -12,27 +12,27 @@ cert_chain: []
12
12
  date: 2012-06-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
- name: activesupport
16
- requirement: &70355882688980 !ruby/object:Gem::Requirement
15
+ name: sanitize
16
+ requirement: &70356218609500 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 3.0.0
21
+ version: 2.0.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70355882688980
24
+ version_requirements: *70356218609500
25
25
  - !ruby/object:Gem::Dependency
26
- name: sanitize
27
- requirement: &70355882688480 !ruby/object:Gem::Requirement
26
+ name: sanitize-url
27
+ requirement: &70356218609000 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
31
31
  - !ruby/object:Gem::Version
32
- version: 2.0.0
32
+ version: 0.1.4
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70355882688480
35
+ version_requirements: *70356218609000
36
36
  description: Work in progress, this will be a generic attribute sanitizer which can
37
37
  be used for sanitizing models and other objects holding data
38
38
  email: