nagybence-railhead_sanitize 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README.rdoc +29 -0
- data/init.rb +1 -0
- data/lib/railhead_sanitize.rb +37 -0
- data/railhead_sanitize.gemspec +18 -0
- metadata +58 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2008 [name of plugin creator]
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
= SimpleSanitize
|
2
|
+
|
3
|
+
SimpleSanitize is a Ruby on Rails plugin that automatically strips tags from input fields.
|
4
|
+
|
5
|
+
== Installation
|
6
|
+
|
7
|
+
Installation is available as gem (recommended):
|
8
|
+
|
9
|
+
config.gem "nagybence-simple_sanitize", :lib => "simple_sanitize", :source => "http://gems.github.com"
|
10
|
+
|
11
|
+
Or as Rails plugin:
|
12
|
+
|
13
|
+
$ ruby script/plugin install git://github.com/nagybence/simple_sanitize.git
|
14
|
+
|
15
|
+
== Usage
|
16
|
+
|
17
|
+
It works fully automatically, but there are two options to modify the default behavior.
|
18
|
+
|
19
|
+
Does not strip a parameter:
|
20
|
+
|
21
|
+
sanitize_fields :except => [:title]
|
22
|
+
|
23
|
+
Uses 'sanitize' instead of 'strip_tags':
|
24
|
+
|
25
|
+
sanitize_fields :allow_tags => [:body]
|
26
|
+
|
27
|
+
== License
|
28
|
+
|
29
|
+
Copyright (c) 2008 Bence Nagy (nagybence@tipogral.hu), released under the MIT license.
|
data/init.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'simple_sanitize'
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module RailheadSanitize
|
2
|
+
def self.included(base)
|
3
|
+
base.extend ClassMethods
|
4
|
+
base.send :include, ActionView::Helpers::SanitizeHelper
|
5
|
+
base.extend ActionView::Helpers::SanitizeHelper::ClassMethods
|
6
|
+
base.class_eval do
|
7
|
+
class_inheritable_reader :sanitize_options
|
8
|
+
before_validation :sanitize_fields
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
module ClassMethods
|
13
|
+
def auto_sanitize(options = {})
|
14
|
+
write_inheritable_attribute(:sanitize_options, {
|
15
|
+
:except => (options[:except] || []),
|
16
|
+
:allow_tags => (options[:allow_tags] || [])
|
17
|
+
})
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def sanitize_fields
|
22
|
+
self.class.columns.each do |column|
|
23
|
+
next unless (column.type == :string || column.type == :text)
|
24
|
+
field = column.name.to_sym
|
25
|
+
value = self[field] && self[field].strip
|
26
|
+
if sanitize_options && sanitize_options[:except].include?(field)
|
27
|
+
self[field] = value
|
28
|
+
elsif sanitize_options && sanitize_options[:allow_tags].include?(field)
|
29
|
+
self[field] = sanitize(value)
|
30
|
+
else
|
31
|
+
self[field] = strip_tags(value)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
ActiveRecord::Base.send :include, RailheadSanitize
|
@@ -0,0 +1,18 @@
|
|
1
|
+
Gem::Specification.new do |s|
|
2
|
+
s.name = "railhead_sanitize"
|
3
|
+
s.version = "0.2.0"
|
4
|
+
s.date = "2009-01-27"
|
5
|
+
s.summary = "RailheadSanitize is a Ruby on Rails plugin that automatically strips tags from input fields."
|
6
|
+
s.email = "nagybence@tipogral.hu"
|
7
|
+
s.homepage = "http://github.com/nagybence/railhead_sanitize"
|
8
|
+
s.description = "RailheadSanitize is a Ruby on Rails plugin that automatically strips tags from input fields."
|
9
|
+
s.has_rdoc = true
|
10
|
+
s.authors = ["Bence Nagy"]
|
11
|
+
s.files = ["MIT-LICENSE",
|
12
|
+
"README.rdoc",
|
13
|
+
"init.rb",
|
14
|
+
"railhead_sanitize.gemspec",
|
15
|
+
"lib/railhead_sanitize.rb"]
|
16
|
+
s.rdoc_options = ["--main", "README.rdoc"]
|
17
|
+
s.extra_rdoc_files = ["README.rdoc"]
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: nagybence-railhead_sanitize
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bence Nagy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-01-27 00:00:00 -08:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description: RailheadSanitize is a Ruby on Rails plugin that automatically strips tags from input fields.
|
17
|
+
email: nagybence@tipogral.hu
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.rdoc
|
24
|
+
files:
|
25
|
+
- MIT-LICENSE
|
26
|
+
- README.rdoc
|
27
|
+
- init.rb
|
28
|
+
- railhead_sanitize.gemspec
|
29
|
+
- lib/railhead_sanitize.rb
|
30
|
+
has_rdoc: true
|
31
|
+
homepage: http://github.com/nagybence/railhead_sanitize
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options:
|
34
|
+
- --main
|
35
|
+
- README.rdoc
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: "0"
|
43
|
+
version:
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.2.0
|
54
|
+
signing_key:
|
55
|
+
specification_version: 2
|
56
|
+
summary: RailheadSanitize is a Ruby on Rails plugin that automatically strips tags from input fields.
|
57
|
+
test_files: []
|
58
|
+
|