proclaim 0.2.4 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 95376276542d333bb59c9ae6c18791bed276b629
4
- data.tar.gz: 3d7f91736e0aabd04624da823c4973b072be0270
3
+ metadata.gz: 499990491b4ea6af55296e35da87462bf821f3ab
4
+ data.tar.gz: 160b0d32c648e01aadd3aa630a0c4ae37e4178ac
5
5
  SHA512:
6
- metadata.gz: 92414f0b8e9f7b4a2059a06868e2e68fd39d5e9dd4e2a8702da1232f07ab2705ec217cf45c8a36aed960b4569671c7abdcab85b157bf1789e0e780bbbb59b1df
7
- data.tar.gz: d6fa347afc769970dd4eb03bacd3d677e6665897db1a5e391e0679db2acae90716f869ef2307ae3828c15fc545faeb9f032a478fb0b57bc64f1fd42a2f7ee590
6
+ metadata.gz: 488d2f108123f326b091a1fe98e5c75702cef2a5f9ae0b1f66b9183ae65b188793007b3a49f759dc9f2cddad67a8430bf8fc9f26cd13c250f2c6c6ac1408539a
7
+ data.tar.gz: 301cba906510fb9f2edc22eee6434ba821cbebacec2992ad816004e176e9c2be01f15087747d6f2158d4c1008e11ecff55fb10dd325183244fbf8326459e6e23
data/CHANGELOG CHANGED
@@ -1,3 +1,7 @@
1
+ v 0.3.0
2
+ - Implemented sanitization for post body, using lists of allowed HTML tags and
3
+ attributes that can be customized via initializer.
4
+
1
5
  v 0.2.4
2
6
  - Added simple format to comments, to preserve line breaks
3
7
 
data/README.md CHANGED
@@ -29,7 +29,7 @@ Proclaim 0.2 works with Rails 4.2 and on, with Ruby 1.9.3 and on. Add it to your
29
29
  Gemfile with:
30
30
 
31
31
  ```ruby
32
- gem 'proclaim', "~> 0.2.4"
32
+ gem 'proclaim', "~> 0.3.0"
33
33
  ```
34
34
 
35
35
  Run `bundle install` to install it.
@@ -105,7 +105,16 @@ Proclaim.author_name_method = :name
105
105
  Proclaim.current_author_method = :current_user
106
106
  Proclaim.authentication_method = :authenticate_user!
107
107
  Proclaim.excerpt_length = 500
108
- Proclaim.editor_toolbar_buttons = ['bold', 'italic', 'underline', 'anchor', 'header1', 'header2', 'quote']
108
+ Proclaim.editor_toolbar_buttons = ['bold', 'italic', 'underline', 'anchor',
109
+ 'header1', 'header2', 'quote']
110
+ Proclaim.editor_whitelist_tags = %w(h1 h2 h3 h4 h5 h6
111
+ div p blockquote
112
+ ul ol li
113
+ a b strong i u
114
+ img figure
115
+ pre sup sub br)
116
+ Proclaim.editor_whitelist_attributes = %w(class id style href title src alt
117
+ align draggable)
109
118
  Proclaim.mailer_sender = nil
110
119
  ```
111
120
 
@@ -141,6 +150,14 @@ Proclaim.mailer_sender = nil
141
150
  The buttons to be displayed on the Medium Editor toolbar. For a full list of
142
151
  options, see the README for [that project][1].
143
152
 
153
+ - **Proclaim.editor_whitelist_tags**
154
+
155
+ A list of all HTML tags that are allowed in the post body.
156
+
157
+ - **Proclaim.editor_whitelist_attributes**
158
+
159
+ A list of all HTML attributes that are allowed in the post body.
160
+
144
161
  - **Proclaim.mailer_sender**
145
162
 
146
163
  The email address to use in the "from" field of all emails from Proclaim. If
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.4
1
+ 0.3.0
@@ -41,6 +41,7 @@ module Proclaim
41
41
  validates_presence_of :title, :body, :author
42
42
  validate :verifyBodyHtml
43
43
 
44
+ before_save :sanitizeBody
44
45
  after_save :notifyBlogSubscribersIfPublished
45
46
 
46
47
  attr_writer :excerpt_length
@@ -78,6 +79,17 @@ module Proclaim
78
79
  end
79
80
  end
80
81
 
82
+ def sanitizeBody
83
+ unless Proclaim.editor_whitelist_tags.blank? and
84
+ Proclaim.editor_whitelist_attributes.blank?
85
+ sanitizer = Rails::Html::WhiteListSanitizer.new
86
+ self.body = sanitizer.sanitize(
87
+ body,
88
+ tags: Proclaim.editor_whitelist_tags,
89
+ attributes: Proclaim.editor_whitelist_attributes)
90
+ end
91
+ end
92
+
81
93
  def takeExcerptOf(text)
82
94
  if excerpt_length >= text.length
83
95
  return text
@@ -21,7 +21,20 @@ Proclaim.setup do |config|
21
21
  #config.excerpt_length = 500
22
22
 
23
23
  # Buttons to display on post editor toolbar
24
- #config.editor_toolbar_buttons = ['bold', 'italic', 'underline', 'anchor', 'header1', 'header2', 'quote']
24
+ #config.editor_toolbar_buttons = ['bold', 'italic', 'underline', 'anchor',
25
+ # 'header1', 'header2', 'quote']
26
+
27
+ # Whitelist of HTML tags to be supported by the editor
28
+ #config.editor_whitelist_tags = %w(h1 h2 h3 h4 h5 h6
29
+ # div p blockquote
30
+ # ul ol li
31
+ # a b strong i u
32
+ # img figure
33
+ # pre sup sub br)
34
+
35
+ # Whitelist of HTML attributes to be supported by the editor
36
+ #config.editor_whitelist_attributes = %w(class id style href title src alt
37
+ # align draggable)
25
38
 
26
39
  # Email address to use in the "from" field of all emails
27
40
  #config.mailer_sender = '"My Blog" <blog@example.com>'
data/lib/proclaim.rb CHANGED
@@ -17,7 +17,20 @@ module Proclaim
17
17
  @@excerpt_length = 500 # 500 characters (won't interrupt words)
18
18
 
19
19
  mattr_accessor :editor_toolbar_buttons
20
- @@editor_toolbar_buttons = ['bold', 'italic', 'underline', 'anchor', 'header1', 'header2', 'quote']
20
+ @@editor_toolbar_buttons = ['bold', 'italic', 'underline', 'anchor',
21
+ 'header1', 'header2', 'quote']
22
+
23
+ mattr_accessor :editor_whitelist_tags
24
+ @@editor_whitelist_tags = %w(h1 h2 h3 h4 h5 h6
25
+ div p blockquote
26
+ ul ol li
27
+ a b strong i u
28
+ img figure
29
+ pre sup sub br)
30
+
31
+ mattr_accessor :editor_whitelist_attributes
32
+ @@editor_whitelist_attributes = %w(class id style href title src alt align
33
+ draggable)
21
34
 
22
35
  mattr_accessor :mailer_sender
23
36
  @@mailer_sender = nil
@@ -2,6 +2,7 @@ require 'rails'
2
2
  require 'coffee-rails'
3
3
  require 'sass-rails'
4
4
  require 'jquery-rails'
5
+ require 'htmlentities'
5
6
  require 'closure_tree'
6
7
  require 'font-awesome-rails'
7
8
  require 'medium-editor-rails'
@@ -1,3 +1,3 @@
1
1
  module Proclaim
2
- VERSION = "0.2.4"
2
+ VERSION = "0.3.0"
3
3
  end
data/proclaim.gemspec CHANGED
@@ -26,6 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.add_dependency "coffee-rails", "~> 4.1"
27
27
  s.add_dependency "sass-rails", "~> 5.0"
28
28
  s.add_dependency "jquery-rails", "~> 4.0"
29
+ s.add_dependency "htmlentities", "~> 4.3"
29
30
  s.add_dependency "nokogiri", "~> 1.6"
30
31
  s.add_dependency "premailer", "~> 1.8"
31
32
  s.add_dependency "closure_tree", "~> 5.2"
@@ -151,7 +151,7 @@ module Proclaim
151
151
 
152
152
  document = Nokogiri::HTML.fragment(post.body)
153
153
  image_tags = document.css("img")
154
- assert_equal 1, image_tags.count
154
+ assert_equal 1, image_tags.count, "Post body should have one image tag"
155
155
 
156
156
  # Note that, now that the image is saved, this URL is different than
157
157
  # the one submitted to :create
@@ -288,7 +288,8 @@ module Proclaim
288
288
 
289
289
  document = Nokogiri::HTML.fragment(post.body)
290
290
  image_tags = document.css("img")
291
- assert_equal 1, image_tags.count
291
+ assert_equal 1, image_tags.count,
292
+ "Post body should contain one image tag"
292
293
 
293
294
  # Note that, now that the image is saved, this URL is different than
294
295
  # the one submitted to :create
@@ -163,7 +163,8 @@ class PostTest < ActionDispatch::IntegrationTest
163
163
 
164
164
  image_tags = Nokogiri::HTML.fragment(image.post.body).css("img")
165
165
 
166
- assert_equal 1, image_tags.length
166
+ assert_equal 1, image_tags.length,
167
+ "Post body should contain one image tag"
167
168
  refute_match root_url, image_tags[0].attribute("src"),
168
169
  "Images should have relative paths"
169
170
  end
@@ -69,7 +69,7 @@ module Proclaim
69
69
 
70
70
  image_tags = Nokogiri::HTML(get_html_part(mail)).css("img")
71
71
 
72
- assert_equal 1, image_tags.length
72
+ assert_equal 1, image_tags.length, "Email should have one image tag"
73
73
  assert_match root_url, image_tags[0].attribute("src"),
74
74
  "Images should have absolute URLs in emails"
75
75
  end
@@ -123,5 +123,12 @@ module Proclaim
123
123
  body: "This is outside.<p>This is inside.</p>")
124
124
  assert_equal "This is outside.", post.excerpt
125
125
  end
126
+
127
+ test "verify body sanitization" do
128
+ post = FactoryGirl.create(:post,
129
+ body: "foo <script>alert('bar');</script>")
130
+
131
+ assert_equal "foo alert('bar');", post.body
132
+ end
126
133
  end
127
134
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: proclaim
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kyle Fazzari
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-17 00:00:00.000000000 Z
11
+ date: 2015-01-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '4.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: htmlentities
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '4.3'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '4.3'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: nokogiri
71
85
  requirement: !ruby/object:Gem::Requirement