acts_as_sanitiled 1.1.4 → 1.1.5
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/VERSION +1 -1
- data/acts_as_sanitiled.gemspec +1 -1
- data/lib/acts_as_sanitiled.rb +6 -2
- data/spec/sanitiled_spec.rb +24 -4
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.1.
|
1
|
+
1.1.5
|
data/acts_as_sanitiled.gemspec
CHANGED
data/lib/acts_as_sanitiled.rb
CHANGED
@@ -14,6 +14,10 @@ module ActsAsSanitiled #:nodoc: all
|
|
14
14
|
klass.extend ClassMethods
|
15
15
|
end
|
16
16
|
|
17
|
+
def self.html_safe_available?
|
18
|
+
"".respond_to?(:html_safe)
|
19
|
+
end
|
20
|
+
|
17
21
|
module ClassMethods
|
18
22
|
def acts_as_textiled(*attributes)
|
19
23
|
raise "only acts_as_sanitized or acts_as_sanitiled can take an options hash" if attributes.last.is_a?(Hash)
|
@@ -58,7 +62,7 @@ module ActsAsSanitiled #:nodoc: all
|
|
58
62
|
string = Sanitize.clean(string, sanitize_options) unless skip_sanitize
|
59
63
|
textiled[attribute.to_s] = string
|
60
64
|
end
|
61
|
-
textiled[attribute.to_s]
|
65
|
+
ActsAsSanitiled.html_safe_available? ? textiled[attribute.to_s].html_safe : textiled[attribute.to_s]
|
62
66
|
elsif type.nil? && self[attribute].nil?
|
63
67
|
nil
|
64
68
|
elsif type_options.include?(type.to_s)
|
@@ -68,7 +72,7 @@ module ActsAsSanitiled #:nodoc: all
|
|
68
72
|
end
|
69
73
|
end
|
70
74
|
|
71
|
-
define_method("#{attribute}_plain", proc { strip_html(__send__(attribute)) if __send__(attribute) } )
|
75
|
+
define_method("#{attribute}_plain", proc { ActsAsSanitiled.html_safe_available? ? strip_html(__send__(attribute)).html_safe : strip_html(__send__(attribute)) if __send__(attribute) } )
|
72
76
|
define_method("#{attribute}_source", proc { __send__("#{attribute}_before_type_cast") } )
|
73
77
|
|
74
78
|
@textiled_attributes << attribute
|
data/spec/sanitiled_spec.rb
CHANGED
@@ -41,16 +41,36 @@ EOF
|
|
41
41
|
@body_plain = "First line\nSecond line with bold\n\nSecond paragraph with special char™, XSS attribute,\nscript>script tag, and unclosed tag."
|
42
42
|
end
|
43
43
|
|
44
|
-
it "should properly textilize and
|
44
|
+
it "should properly textilize and sanitize by default" do
|
45
45
|
@story.description.should.equal @desc_html
|
46
|
-
@story.
|
46
|
+
@story.body.should.equal @body_html
|
47
|
+
end
|
48
|
+
|
49
|
+
it "should mark textilized and sanitized output as html safe" do
|
50
|
+
@story.description.should.be :html_safe?
|
51
|
+
@story.body.should.be :html_safe?
|
52
|
+
end if ActsAsSanitiled.html_safe_available?
|
53
|
+
|
54
|
+
it "should properly strip html when given the 'plain' option" do
|
47
55
|
@story.description(:plain).should.equal @desc_plain
|
56
|
+
@story.body(:plain).should.equal @body_plain
|
57
|
+
end
|
48
58
|
|
49
|
-
|
59
|
+
it "should mark output stripped of html as html safe" do
|
60
|
+
@story.description(:plain).should.be :html_safe?
|
61
|
+
@story.body(:plain).should.be :html_safe?
|
62
|
+
end if ActsAsSanitiled.html_safe_available?
|
63
|
+
|
64
|
+
it "should leave unchanged when given the 'source' option" do
|
65
|
+
@story.description(:source).should.equal @desc_textile
|
50
66
|
@story.body(:source).should.equal @body_textile
|
51
|
-
@story.body(:plain).should.equal @body_plain
|
52
67
|
end
|
53
68
|
|
69
|
+
it "should not mark raw source as html safe" do
|
70
|
+
@story.description(:source).should.not.be :html_safe?
|
71
|
+
@story.body(:source).should.not.be :html_safe?
|
72
|
+
end if ActsAsSanitiled.html_safe_available?
|
73
|
+
|
54
74
|
it "should raise when given a non-sensical option" do
|
55
75
|
proc{ @story.description(:cassadaga) }.should.raise
|
56
76
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: acts_as_sanitiled
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 25
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 1
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 1.1.
|
9
|
+
- 5
|
10
|
+
version: 1.1.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Gabe da Silveira
|