sanitize-rails 0.6.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,4 @@
1
+ html
2
+ pkg
3
+ .*.sw?
4
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec
data/Rakefile CHANGED
@@ -1,40 +1,22 @@
1
- require 'rake'
2
- require 'rdoc/task'
3
-
4
- require 'lib/sanitize/rails'
5
-
6
1
  begin
7
- require 'jeweler'
8
- Jeweler::Tasks.new do |gemspec|
9
- gemspec.name = 'sanitize-rails'
10
-
11
- gemspec.summary = 'A sanitizer bridge for Rails applications'
12
- gemspec.authors = ['Marcello Barnaba']
13
- gemspec.email = 'vjt@openssl.it'
14
- gemspec.homepage = 'http://github.com/vjt/sanitize-rails'
15
-
16
- gemspec.files = %w( README.md Rakefile rails/init.rb ) + Dir['lib/**/*']
17
- gemspec.extra_rdoc_files = %w( README.md )
18
- gemspec.has_rdoc = true
19
-
20
- gemspec.version = Sanitize::Rails::Version
21
- gemspec.require_path = 'lib'
22
-
23
- gemspec.add_dependency('rails', '~> 3.0')
24
- gemspec.add_dependency('sanitize')
25
- end
2
+ require 'bundler/setup'
26
3
  rescue LoadError
27
- puts 'Jeweler not available. Install it with: gem install jeweler'
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
28
5
  end
29
6
 
30
- desc 'Generate the rdoc'
31
- Rake::RDocTask.new do |rdoc|
32
- rdoc.rdoc_files.add %w( README.md lib/**/*.rb )
7
+ require 'rdoc/task'
33
8
 
34
- rdoc.main = 'README.md'
35
- rdoc.title = 'Sanitizer-Rails'
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'doc'
11
+ rdoc.title = 'Sanitize-Rails'
12
+ rdoc.options << '--line-numbers'
13
+
14
+ rdoc.rdoc_files.include 'README.md'
15
+ rdoc.rdoc_files.include 'lib/**/*.rb'
36
16
  end
37
17
 
18
+ Bundler::GemHelper.install_tasks
19
+
38
20
  desc 'Will someone help write tests?'
39
21
  task :default do
40
22
  puts
@@ -0,0 +1,62 @@
1
+ HTML::WhiteListSanitizer.allowed_css_properties = %w(text-align background-color)
2
+ HTML::WhiteListSanitizer.shorthand_css_properties = %w()
3
+ HTML::WhiteListSanitizer.allowed_css_keywords = %w(left center right justify rgb)
4
+
5
+ engine = HTML::WhiteListSanitizer.new
6
+
7
+ css_sanitizer = lambda {|options|
8
+ node = options[:node]
9
+ if node.present? && node.element? && node['style'].present?
10
+ node['style'] = engine.sanitize_css node['style']
11
+ end
12
+ }
13
+
14
+ div_transformer = lambda {|options|
15
+ node = options[:node]
16
+ if node.present? && node.element? && node.name.downcase == 'div'
17
+ node.name = 'p'
18
+ end
19
+ }
20
+
21
+ ie_cleaner = lambda {|options|
22
+ node = options[:node]
23
+ return unless node.present? && node.element?
24
+
25
+ if align = node['align']
26
+ node['style'] = "text-align: #{align};"
27
+ end
28
+
29
+ if node.name.downcase == 'font'
30
+ node.name = 'span'
31
+ end
32
+ }
33
+
34
+ Sanitize::Rails.configure(
35
+ :elements => %w[ a b blockquote br div img em i li ol p span strong u ul ],
36
+
37
+ :attributes => {
38
+ :all => ['style'],
39
+ 'a' => ['href'],
40
+ 'img' => ['src']
41
+ },
42
+
43
+ :add_attributes => {
44
+ 'a' => {
45
+ 'rel' => 'nofollow',
46
+ 'target' => '_blank'
47
+ }
48
+ },
49
+
50
+ :protocols => {
51
+ 'a' => {'href' => ['ftp', 'http', 'https', 'mailto', :relative]},
52
+ 'img' => {'src' => ['http', 'https']}
53
+ },
54
+
55
+ :transformers => [css_sanitizer, div_transformer, ie_cleaner],
56
+
57
+ :whitespace_elements => %w(
58
+ address article aside blockquote dd dl dt footer
59
+ h1 h2 h3 h4 h5 h6 header hgroup hr nav pre section
60
+ tr td option input
61
+ )
62
+ )
@@ -4,7 +4,6 @@ require 'sanitize'
4
4
  require 'sanitize/railtie' if defined? Rails
5
5
 
6
6
  module Sanitize::Rails
7
- Version = '0.6.2'
8
7
 
9
8
  # Configures the sanitizer with the given `config` hash.
10
9
  #
@@ -0,0 +1,5 @@
1
+ module Sanitize
2
+ module Rails
3
+ VERSION = '0.7.0'
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ #
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+
5
+ require 'sanitize/rails/version'
6
+
7
+ Gem::Specification.new do |s|
8
+ s.name = "sanitize-rails"
9
+ s.version = Sanitize::Rails::VERSION
10
+ s.date = "2013-07-15"
11
+ s.authors = ["Marcello Barnaba"]
12
+ s.email = ["vjt@openssl.it"]
13
+ s.homepage = "http://github.com/vjt/sanitize-rails"
14
+ s.summary = "A sanitizer bridge for Rails applications"
15
+
16
+ s.require_paths = ["lib"]
17
+ s.files = `git ls-files`.split("\n")
18
+
19
+ s.add_dependency "rails", "~> 3.0"
20
+ s.add_dependency "sanitize"
21
+ end
metadata CHANGED
@@ -1,96 +1,82 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: sanitize-rails
3
- version: !ruby/object:Gem::Version
4
- hash: 3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.7.0
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 6
9
- - 2
10
- version: 0.6.2
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Marcello Barnaba
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2012-10-04 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2013-07-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: rails
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: &74022620 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
18
+ requirements:
26
19
  - - ~>
27
- - !ruby/object:Gem::Version
28
- hash: 7
29
- segments:
30
- - 3
31
- - 0
32
- version: "3.0"
20
+ - !ruby/object:Gem::Version
21
+ version: '3.0'
33
22
  type: :runtime
34
- version_requirements: *id001
35
- - !ruby/object:Gem::Dependency
36
- name: sanitize
37
23
  prerelease: false
38
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *74022620
25
+ - !ruby/object:Gem::Dependency
26
+ name: sanitize
27
+ requirement: &74022110 !ruby/object:Gem::Requirement
39
28
  none: false
40
- requirements:
41
- - - ">="
42
- - !ruby/object:Gem::Version
43
- hash: 3
44
- segments:
45
- - 0
46
- version: "0"
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
47
33
  type: :runtime
48
- version_requirements: *id002
34
+ prerelease: false
35
+ version_requirements: *74022110
49
36
  description:
50
- email: vjt@openssl.it
37
+ email:
38
+ - vjt@openssl.it
51
39
  executables: []
52
-
53
40
  extensions: []
54
-
55
- extra_rdoc_files:
56
- - README.md
57
- files:
41
+ extra_rdoc_files: []
42
+ files:
43
+ - .gitignore
44
+ - Gemfile
58
45
  - README.md
59
46
  - Rakefile
47
+ - example/sanitizer.rb
60
48
  - lib/sanitize/rails.rb
49
+ - lib/sanitize/rails/version.rb
61
50
  - lib/sanitize/railtie.rb
51
+ - sanitize-rails.gemspec
62
52
  homepage: http://github.com/vjt/sanitize-rails
63
53
  licenses: []
64
-
65
54
  post_install_message:
66
55
  rdoc_options: []
67
-
68
- require_paths:
56
+ require_paths:
69
57
  - lib
70
- required_ruby_version: !ruby/object:Gem::Requirement
58
+ required_ruby_version: !ruby/object:Gem::Requirement
71
59
  none: false
72
- requirements:
73
- - - ">="
74
- - !ruby/object:Gem::Version
75
- hash: 3
76
- segments:
60
+ requirements:
61
+ - - ! '>='
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ segments:
77
65
  - 0
78
- version: "0"
79
- required_rubygems_version: !ruby/object:Gem::Requirement
66
+ hash: -72034417
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
68
  none: false
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- hash: 3
85
- segments:
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ segments:
86
74
  - 0
87
- version: "0"
75
+ hash: -72034417
88
76
  requirements: []
89
-
90
77
  rubyforge_project:
91
- rubygems_version: 1.8.12
78
+ rubygems_version: 1.8.11
92
79
  signing_key:
93
80
  specification_version: 3
94
81
  summary: A sanitizer bridge for Rails applications
95
82
  test_files: []
96
-