sanitize-rails 0.7.2 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +3 -2
- data/.travis.yml +5 -0
- data/README.md +1 -1
- data/Rakefile +9 -5
- data/lib/sanitize/rails.rb +19 -5
- data/lib/sanitize/rails/version.rb +1 -1
- data/sanitize-rails.gemspec +3 -3
- data/test/sanitize_rails_engine_test.rb +53 -0
- data/test/sanitize_rails_string_extension_test.rb +38 -0
- data/test/test_helper.rb +2 -0
- metadata +15 -21
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e0853ed8dac0969d869f6bc326b4c39c6a13f8ba
|
4
|
+
data.tar.gz: 0987e863569b876662c020c747414f57544ac6ac
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c802cc9613d49098c9d870e7cc7f02bda1daa1ebb62a70392aba026090a8fd0783c0b2bf95787933434814f92329a9448e11fe8a5728bf0102b4b24c63f94fe6
|
7
|
+
data.tar.gz: 4aad63b7ac6c064abae2beaf3302699acad762b2c35fb489ea249602313791c3598fb8fb43e212e9681a36189f80c735da116126f32d7acb7ca684b6a62d2aee
|
data/.gitignore
CHANGED
data/.travis.yml
ADDED
data/README.md
CHANGED
data/Rakefile
CHANGED
@@ -17,9 +17,13 @@ end
|
|
17
17
|
|
18
18
|
Bundler::GemHelper.install_tasks
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
require 'rake/testtask'
|
21
|
+
|
22
|
+
Rake::TestTask.new do |t|
|
23
|
+
t.libs.push 'test'
|
24
|
+
t.test_files = FileList['test/*_test.rb']
|
25
|
+
t.warning = true
|
26
|
+
t.verbose = true
|
25
27
|
end
|
28
|
+
|
29
|
+
task default: :test
|
data/lib/sanitize/rails.rb
CHANGED
@@ -28,19 +28,33 @@ module Sanitize::Rails
|
|
28
28
|
|
29
29
|
# Returns a memoized instance of the Engine with the
|
30
30
|
# configuration passed to the +configure+ method or with
|
31
|
-
# the
|
31
|
+
# the ActionView's default config
|
32
32
|
#
|
33
33
|
def cleaner
|
34
|
-
|
34
|
+
@@config ||= begin
|
35
|
+
{
|
36
|
+
:elements => ::ActionView::Base.sanitized_allowed_tags.to_a,
|
37
|
+
:attributes => { :all => ::ActionView::Base.sanitized_allowed_attributes.to_a},
|
38
|
+
:protocols => { :all => ::ActionView::Base.sanitized_allowed_protocols.to_a }
|
39
|
+
}
|
40
|
+
rescue
|
41
|
+
warn "ActionView not available, falling back to Sanitize's BASIC config"
|
42
|
+
::Sanitize::Config::BASIC
|
43
|
+
end
|
44
|
+
@sanitizer ||= ::Sanitize.new(@@config)
|
35
45
|
end
|
36
46
|
|
37
|
-
# Returns a copy of the given `string` after sanitizing it
|
47
|
+
# Returns a copy of the given `string` after sanitizing it and marking it
|
48
|
+
# as `html_safe`
|
38
49
|
#
|
50
|
+
# Ensuring this methods return instances of ActiveSupport::SafeBuffer
|
51
|
+
# means that text passed through `Sanitize::Rails::Engine.clean`
|
52
|
+
# will not be escaped by ActionView's XSS filtering utilities.
|
39
53
|
def clean(string)
|
40
|
-
string.dup.tap {|s| clean!(s)}
|
54
|
+
::ActiveSupport::SafeBuffer.new string.dup.tap { |s| clean!(s) }
|
41
55
|
end
|
42
56
|
|
43
|
-
# Sanitizes the given `string` in place
|
57
|
+
# Sanitizes the given `string` in place and does NOT mark it as `html_safe`
|
44
58
|
#
|
45
59
|
def clean!(string)
|
46
60
|
cleaner.clean!(string)
|
data/sanitize-rails.gemspec
CHANGED
@@ -7,9 +7,9 @@ require 'sanitize/rails/version'
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "sanitize-rails"
|
9
9
|
s.version = Sanitize::Rails::VERSION
|
10
|
-
s.date = "
|
11
|
-
s.authors = ["Marcello Barnaba"]
|
12
|
-
s.email = ["vjt@openssl.it"]
|
10
|
+
s.date = "2014-03-14"
|
11
|
+
s.authors = ["Marcello Barnaba", "Damien Wilson"]
|
12
|
+
s.email = ["vjt@openssl.it", "damien@mindglob.com"]
|
13
13
|
s.homepage = "http://github.com/vjt/sanitize-rails"
|
14
14
|
s.summary = "A sanitizer bridge for Rails applications"
|
15
15
|
s.license = "MIT"
|
@@ -0,0 +1,53 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'action_view'
|
4
|
+
require 'sanitize'
|
5
|
+
require 'sanitize/rails'
|
6
|
+
|
7
|
+
# Test suite for Sanitize::Rails::Engine
|
8
|
+
class SanitizeRailsEngineTest < MiniTest::Unit::TestCase
|
9
|
+
def setup
|
10
|
+
@engine = Sanitize::Rails::Engine
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_respond_to_configure
|
14
|
+
assert_respond_to @engine, :configure
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_respond_to_cleaner
|
18
|
+
assert_respond_to @engine, :cleaner
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_cleaner_returns_instance_of_sanitize
|
22
|
+
assert_kind_of Sanitize, @engine.cleaner
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_respond_to_clean_bang
|
26
|
+
assert_respond_to @engine, :clean!
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_clean_bang_modifies_string_in_place
|
30
|
+
string = %Q|<script>alert("hello world")</script>|
|
31
|
+
@engine.clean! string
|
32
|
+
assert_equal string, %q|alert("hello world")|
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_respond_to_clean
|
36
|
+
assert_respond_to @engine, :clean
|
37
|
+
end
|
38
|
+
|
39
|
+
def test_clean_does_not_modify_string_in_place
|
40
|
+
string = %Q|<script>alert("hello world")</script>|
|
41
|
+
new_string = @engine.clean string
|
42
|
+
assert_equal string, %Q|<script>alert("hello world")</script>|
|
43
|
+
assert_equal new_string, 'alert("hello world")'
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_clean_returns_safe_buffers
|
47
|
+
string = %Q|<script>alert("hello world")</script>|
|
48
|
+
assert_instance_of String, string
|
49
|
+
|
50
|
+
new_string = @engine.clean string
|
51
|
+
assert_instance_of ::ActiveSupport::SafeBuffer, new_string
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
|
3
|
+
require 'action_view'
|
4
|
+
require 'sanitize'
|
5
|
+
require 'sanitize/rails'
|
6
|
+
|
7
|
+
# Test suite for Sanitize::Rails::Engine
|
8
|
+
class SanitizeRailsStringExtensionTest < MiniTest::Unit::TestCase
|
9
|
+
SanitizableString = Class.new(String) { include Sanitize::Rails::String }
|
10
|
+
|
11
|
+
def setup
|
12
|
+
@string = SanitizableString.new %Q|<script>alert("hello world")</script>|
|
13
|
+
end
|
14
|
+
|
15
|
+
def test_respond_to_sanitize_as_html_bang
|
16
|
+
assert_respond_to @string, :sanitize_as_html!
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_sanitize_as_html_bang_does_not_return_safe_buffers
|
20
|
+
sanitizable_string = @string.dup
|
21
|
+
assert_instance_of SanitizableString, sanitizable_string
|
22
|
+
|
23
|
+
new_string = sanitizable_string.sanitize_as_html!
|
24
|
+
assert_instance_of String, new_string
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_respond_to_sanitize_as_html
|
28
|
+
assert_respond_to @string, :sanitize_as_html
|
29
|
+
end
|
30
|
+
|
31
|
+
def test_sanitize_as_html_returns_safe_buffers
|
32
|
+
sanitizable_string = @string.dup
|
33
|
+
assert_instance_of SanitizableString, sanitizable_string
|
34
|
+
|
35
|
+
new_string = sanitizable_string.sanitize_as_html
|
36
|
+
assert_instance_of ::ActiveSupport::SafeBuffer, new_string
|
37
|
+
end
|
38
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,36 +1,33 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sanitize-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.8.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Marcello Barnaba
|
8
|
+
- Damien Wilson
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2014-03-14 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
17
|
requirements:
|
19
|
-
- -
|
18
|
+
- - '>='
|
20
19
|
- !ruby/object:Gem::Version
|
21
20
|
version: '3.0'
|
22
21
|
type: :runtime
|
23
22
|
prerelease: false
|
24
23
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
24
|
requirements:
|
27
|
-
- -
|
25
|
+
- - '>='
|
28
26
|
- !ruby/object:Gem::Version
|
29
27
|
version: '3.0'
|
30
28
|
- !ruby/object:Gem::Dependency
|
31
29
|
name: sanitize
|
32
30
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
31
|
requirements:
|
35
32
|
- - ~>
|
36
33
|
- !ruby/object:Gem::Version
|
@@ -38,7 +35,6 @@ dependencies:
|
|
38
35
|
type: :runtime
|
39
36
|
prerelease: false
|
40
37
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
38
|
requirements:
|
43
39
|
- - ~>
|
44
40
|
- !ruby/object:Gem::Version
|
@@ -46,11 +42,13 @@ dependencies:
|
|
46
42
|
description:
|
47
43
|
email:
|
48
44
|
- vjt@openssl.it
|
45
|
+
- damien@mindglob.com
|
49
46
|
executables: []
|
50
47
|
extensions: []
|
51
48
|
extra_rdoc_files: []
|
52
49
|
files:
|
53
50
|
- .gitignore
|
51
|
+
- .travis.yml
|
54
52
|
- Gemfile
|
55
53
|
- README.md
|
56
54
|
- Rakefile
|
@@ -59,35 +57,31 @@ files:
|
|
59
57
|
- lib/sanitize/rails/version.rb
|
60
58
|
- lib/sanitize/railtie.rb
|
61
59
|
- sanitize-rails.gemspec
|
60
|
+
- test/sanitize_rails_engine_test.rb
|
61
|
+
- test/sanitize_rails_string_extension_test.rb
|
62
|
+
- test/test_helper.rb
|
62
63
|
homepage: http://github.com/vjt/sanitize-rails
|
63
64
|
licenses:
|
64
65
|
- MIT
|
66
|
+
metadata: {}
|
65
67
|
post_install_message:
|
66
68
|
rdoc_options: []
|
67
69
|
require_paths:
|
68
70
|
- lib
|
69
71
|
required_ruby_version: !ruby/object:Gem::Requirement
|
70
|
-
none: false
|
71
72
|
requirements:
|
72
|
-
- -
|
73
|
+
- - '>='
|
73
74
|
- !ruby/object:Gem::Version
|
74
75
|
version: '0'
|
75
|
-
segments:
|
76
|
-
- 0
|
77
|
-
hash: -1813674456041994322
|
78
76
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
79
|
-
none: false
|
80
77
|
requirements:
|
81
|
-
- -
|
78
|
+
- - '>='
|
82
79
|
- !ruby/object:Gem::Version
|
83
80
|
version: '0'
|
84
|
-
segments:
|
85
|
-
- 0
|
86
|
-
hash: -1813674456041994322
|
87
81
|
requirements: []
|
88
82
|
rubyforge_project:
|
89
|
-
rubygems_version:
|
83
|
+
rubygems_version: 2.0.3
|
90
84
|
signing_key:
|
91
|
-
specification_version:
|
85
|
+
specification_version: 4
|
92
86
|
summary: A sanitizer bridge for Rails applications
|
93
87
|
test_files: []
|