sanitize_model_attributes 0.0.6 → 0.0.7
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 72b389d9de73b761b3d3ffa1f6dacfa7536e718a
|
4
|
+
data.tar.gz: 947cceddcc3b8396671a194e144ba27a0c6fba32
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9b157582ce0f78c0faf60e42c046f7c41030f0da6ff00b3223e7930d08151b00d73018bb2b93063929af054c5bab7a24a4b704b46962dac821164f9c4c764814
|
7
|
+
data.tar.gz: 51721deca3896a974e51189dfce731c3d1e6529601f1616cbd9eafb0ed45363e8f1aeb5e722f62f14ab35c3cb2a3f43e0e1e4d83ba0e03228fb0f646ba57d043
|
@@ -1,10 +1,21 @@
|
|
1
1
|
require 'sanitize_model_attributes/version'
|
2
|
-
require '
|
2
|
+
require 'sanitize_model_attributes/configuration'
|
3
|
+
require 'loofah'
|
3
4
|
|
4
5
|
module SanitizeModelAttributes
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
class << self
|
7
|
+
def included(base)
|
8
|
+
class << base
|
9
|
+
include ClassMethods
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def configure
|
14
|
+
yield(configuration)
|
15
|
+
end
|
16
|
+
|
17
|
+
def configuration
|
18
|
+
@configuration ||= Configuration.new
|
8
19
|
end
|
9
20
|
end
|
10
21
|
|
@@ -13,7 +24,14 @@ module SanitizeModelAttributes
|
|
13
24
|
args.each do |attribute_name|
|
14
25
|
self.class_eval do
|
15
26
|
define_method "#{attribute_name}=".to_sym do |attribute_value|
|
16
|
-
|
27
|
+
unless attribute_value.frozen?
|
28
|
+
attribute_value = Loofah.fragment(attribute_value).scrub!(:strip).text
|
29
|
+
|
30
|
+
SanitizeModelAttributes.configuration.white_character_maps.each do |k, v|
|
31
|
+
attribute_value = attribute_value.gsub(/#{k}/, v)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
17
35
|
write_attribute attribute_name.to_sym, attribute_value
|
18
36
|
end
|
19
37
|
end
|
@@ -18,6 +18,6 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.add_dependency "
|
21
|
+
spec.add_dependency "loofah", "~> 2"
|
22
22
|
spec.add_development_dependency 'minitest'
|
23
23
|
end
|
@@ -21,6 +21,38 @@ class TestString < Minitest::Test
|
|
21
21
|
assert instance.respond_to? :model_name=
|
22
22
|
end
|
23
23
|
|
24
|
+
def test_to_escape
|
25
|
+
instance = @klass.new
|
26
|
+
|
27
|
+
def instance.write_attribute(name, value)
|
28
|
+
instance_variable_set("@#{name}".to_sym, value)
|
29
|
+
end
|
30
|
+
|
31
|
+
instance.name = '&&&'
|
32
|
+
assert_equal '&&&', instance.instance_variable_get(:@name)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_to_escape_with_whitelist
|
36
|
+
instance = @klass.new
|
37
|
+
|
38
|
+
def instance.write_attribute(name, value)
|
39
|
+
instance_variable_set("@#{name}".to_sym, value)
|
40
|
+
end
|
41
|
+
|
42
|
+
SanitizeModelAttributes.configure do |config|
|
43
|
+
config.white_character_maps = {
|
44
|
+
'&' => '&'
|
45
|
+
}
|
46
|
+
end
|
47
|
+
|
48
|
+
instance.name = '&&&'
|
49
|
+
assert_equal '&&&', instance.instance_variable_get(:@name)
|
50
|
+
|
51
|
+
SanitizeModelAttributes.configure do |config|
|
52
|
+
config.white_character_maps = {}
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
24
56
|
def test_to_run
|
25
57
|
instance = @klass.new
|
26
58
|
|
@@ -28,7 +60,7 @@ class TestString < Minitest::Test
|
|
28
60
|
instance_variable_set("@#{name}".to_sym, value)
|
29
61
|
end
|
30
62
|
|
31
|
-
instance.name = '<strong>
|
63
|
+
instance.name = '<div></div><p><strong>hoge</strong></p><div>hoge</div>'
|
32
64
|
assert_equal 'hogehoge', instance.instance_variable_get(:@name)
|
33
65
|
end
|
34
66
|
|
metadata
CHANGED
@@ -1,29 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sanitize_model_attributes
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Takashi CHIBA
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: loofah
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '2'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '2'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -51,6 +51,7 @@ files:
|
|
51
51
|
- README.md
|
52
52
|
- Rakefile
|
53
53
|
- lib/sanitize_model_attributes.rb
|
54
|
+
- lib/sanitize_model_attributes/configuration.rb
|
54
55
|
- lib/sanitize_model_attributes/version.rb
|
55
56
|
- sanitize_model_attributes.gemspec
|
56
57
|
- test/test_sanitize_model_attributes.rb
|
@@ -74,7 +75,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
74
75
|
version: '0'
|
75
76
|
requirements: []
|
76
77
|
rubyforge_project:
|
77
|
-
rubygems_version: 2.4.
|
78
|
+
rubygems_version: 2.4.5
|
78
79
|
signing_key:
|
79
80
|
specification_version: 4
|
80
81
|
summary: Sanitize ActiveRecord attributes.
|