rails_xss 0.1.3 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -48,7 +48,7 @@ task :test => :check_dependencies
48
48
 
49
49
  task :default => :test
50
50
 
51
- require 'rake/rdoctask'
51
+ require 'rdoc/task'
52
52
  Rake::RDocTask.new do |rdoc|
53
53
  version = File.exist?('VERSION') ? File.read('VERSION') : ""
54
54
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.3.0
@@ -1,4 +1,10 @@
1
- require 'erubis/helpers/rails_helper'
1
+ # stop erubis from printing it's version number all the time
2
+ old_stdout = $stdout
3
+ File.open("/dev/null", "w") do |f|
4
+ $stdout = f
5
+ require 'erubis/helpers/rails_helper'
6
+ $stdout = old_stdout
7
+ end
2
8
 
3
9
  module RailsXss
4
10
  class Erubis < ::Erubis::Eruby
metadata CHANGED
@@ -1,45 +1,41 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rails_xss
3
- version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 3
9
- version: 0.1.3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ prerelease:
10
6
  platform: ruby
11
- authors:
7
+ authors:
12
8
  - joloudov
13
9
  autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
-
17
- date: 2010-07-14 00:00:00 +04:00
18
- default_executable:
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
12
+ date: 2012-08-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
21
15
  name: erubis
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- requirements:
25
- - - ">="
26
- - !ruby/object:Gem::Version
27
- segments:
28
- - 2
29
- - 6
30
- - 5
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
31
21
  version: 2.6.5
32
22
  type: :development
33
- version_requirements: *id001
34
- description: This plugin replaces the default ERB template handlers with erubis, and switches the behaviour to escape by default rather than requiring you to escape. This is consistent with the behaviour in Rails 3.0.
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 2.6.5
30
+ description: This plugin replaces the default ERB template handlers with erubis, and
31
+ switches the behaviour to escape by default rather than requiring you to escape.
32
+ This is consistent with the behaviour in Rails 3.0.
35
33
  email: joloudov@gmail.com
36
34
  executables: []
37
-
38
35
  extensions: []
39
-
40
- extra_rdoc_files:
36
+ extra_rdoc_files:
41
37
  - README.markdown
42
- files:
38
+ files:
43
39
  - MIT-LICENSE
44
40
  - README.markdown
45
41
  - Rakefile
@@ -50,46 +46,28 @@ files:
50
46
  - lib/rails_xss/erubis.rb
51
47
  - lib/rails_xss/string_ext.rb
52
48
  - lib/tasks/rails_xss_tasks.rake
53
- has_rdoc: true
54
49
  homepage: http://github.com/joloudov/rails_xss
55
50
  licenses: []
56
-
57
51
  post_install_message:
58
- rdoc_options:
59
- - --charset=UTF-8
60
- require_paths:
52
+ rdoc_options: []
53
+ require_paths:
61
54
  - lib
62
- required_ruby_version: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- segments:
67
- - 0
68
- version: "0"
69
- required_rubygems_version: !ruby/object:Gem::Requirement
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- segments:
74
- - 0
75
- version: "0"
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ required_rubygems_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
76
67
  requirements: []
77
-
78
68
  rubyforge_project:
79
- rubygems_version: 1.3.7
69
+ rubygems_version: 1.8.24
80
70
  signing_key:
81
71
  specification_version: 3
82
72
  summary: A plugin for rails 2.3 apps which switches the default to escape by default
83
- test_files:
84
- - test/deprecated_output_safety_test.rb
85
- - test/output_safety_test.rb
86
- - test/form_tag_helper_test.rb
87
- - test/form_helper_test.rb
88
- - test/test_helper.rb
89
- - test/erb_util_test.rb
90
- - test/date_helper_test.rb
91
- - test/active_record_helper_test.rb
92
- - test/caching_test.rb
93
- - test/text_helper_test.rb
94
- - test/asset_tag_helper_test.rb
95
- - test/rails_xss_test.rb
73
+ test_files: []
@@ -1,74 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ActiveRecordHelperTest < ActionView::TestCase
4
- silence_warnings do
5
- Post = Struct.new("Post", :title, :author_name, :body, :secret, :written_on)
6
- Post.class_eval do
7
- alias_method :title_before_type_cast, :title unless respond_to?(:title_before_type_cast)
8
- alias_method :body_before_type_cast, :body unless respond_to?(:body_before_type_cast)
9
- alias_method :author_name_before_type_cast, :author_name unless respond_to?(:author_name_before_type_cast)
10
- end
11
- end
12
-
13
- def setup_post
14
- @post = Post.new
15
- def @post.errors
16
- Class.new {
17
- def on(field)
18
- case field.to_s
19
- when "author_name"
20
- "can't be empty"
21
- when "body"
22
- true
23
- else
24
- false
25
- end
26
- end
27
- def empty?() false end
28
- def count() 1 end
29
- def full_messages() [ "Author name can't be empty" ] end
30
- }.new
31
- end
32
-
33
- def @post.new_record?() true end
34
- def @post.to_param() nil end
35
-
36
- def @post.column_for_attribute(attr_name)
37
- Post.content_columns.select { |column| column.name == attr_name }.first
38
- end
39
-
40
- silence_warnings do
41
- def Post.content_columns() [ Column.new(:string, "title", "Title"), Column.new(:text, "body", "Body") ] end
42
- end
43
-
44
- @post.title = "Hello World"
45
- @post.author_name = ""
46
- @post.body = "Back to the hill and over it again!"
47
- @post.secret = 1
48
- @post.written_on = Date.new(2004, 6, 15)
49
- end
50
-
51
- def setup
52
- setup_post
53
-
54
- @response = ActionController::TestResponse.new
55
-
56
- @controller = Object.new
57
- def @controller.url_for(options)
58
- options = options.symbolize_keys
59
-
60
- [options[:action], options[:id].to_param].compact.join('/')
61
- end
62
- end
63
-
64
- def test_text_field_with_errors_is_safe
65
- assert text_field("post", "author_name").html_safe?
66
- end
67
-
68
- def test_text_field_with_errors
69
- assert_dom_equal(
70
- %(<div class="fieldWithErrors"><input id="post_author_name" name="post[author_name]" size="30" type="text" value="" /></div>),
71
- text_field("post", "author_name")
72
- )
73
- end
74
- end
@@ -1,49 +0,0 @@
1
- require 'test_helper'
2
-
3
- class AssetTagHelperTest < ActionView::TestCase
4
- def setup
5
- @controller = Class.new do
6
- attr_accessor :request
7
- def url_for(*args) "http://www.example.com" end
8
- end.new
9
- end
10
-
11
- def test_auto_discovery_link_tag
12
- assert_dom_equal(%(<link href="http://www.example.com" rel="Not so alternate" title="ATOM" type="application/atom+xml" />),
13
- auto_discovery_link_tag(:atom, {}, {:rel => "Not so alternate"}))
14
- end
15
-
16
- def test_javascript_include_tag_with_blank_asset_id
17
- ENV["RAILS_ASSET_ID"] = ""
18
- assert_dom_equal(%(<script src="/javascripts/test.js" type="text/javascript"></script>\n<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>),
19
- javascript_include_tag("test", :defaults))
20
- end
21
-
22
- def test_javascript_include_tag_with_given_asset_id
23
- ENV["RAILS_ASSET_ID"] = "1"
24
- assert_dom_equal(%(<script src="/javascripts/prototype.js?1" type="text/javascript"></script>\n<script src="/javascripts/effects.js?1" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js?1" type="text/javascript"></script>\n<script src="/javascripts/controls.js?1" type="text/javascript"></script>\n<script src="/javascripts/application.js?1" type="text/javascript"></script>),
25
- javascript_include_tag(:defaults))
26
- ENV["RAILS_ASSET_ID"] = ""
27
- end
28
-
29
- def test_javascript_include_tag_is_html_safe
30
- assert javascript_include_tag(:defaults).html_safe?
31
- assert javascript_include_tag("prototype").html_safe?
32
- end
33
-
34
- def test_stylesheet_link_tag
35
- assert_dom_equal(%(<link href="http://www.example.com/styles/style.css" media="screen" rel="stylesheet" type="text/css" />),
36
- stylesheet_link_tag("http://www.example.com/styles/style"))
37
- end
38
-
39
- def test_stylesheet_link_tag_is_html_safe
40
- assert stylesheet_link_tag('dir/file').html_safe?
41
- assert stylesheet_link_tag('dir/other/file', 'dir/file2').html_safe?
42
- assert stylesheet_tag('dir/file', {}).html_safe?
43
- end
44
-
45
- def test_image_tag
46
- assert_dom_equal(%(<img alt="Mouse" onmouseover="this.src='/images/mouse_over.png'" onmouseout="this.src='/images/mouse.png'" src="/images/mouse.png" />),
47
- image_tag("mouse.png", :mouseover => image_path("mouse_over.png")))
48
- end
49
- end
data/test/caching_test.rb DELETED
@@ -1,43 +0,0 @@
1
- require 'test_helper'
2
-
3
- CACHE_DIR = 'test_cache'
4
- # Don't change '/../temp/' cavalierly or you might hose something you don't want hosed
5
- FILE_STORE_PATH = File.join(File.dirname(__FILE__), '/../temp/', CACHE_DIR)
6
- ActionController::Base.page_cache_directory = FILE_STORE_PATH
7
- ActionController::Base.cache_store = :file_store, FILE_STORE_PATH
8
-
9
- class FragmentCachingTestController < ActionController::Base
10
- def some_action; end;
11
- end
12
-
13
- class FragmentCachingTest < ActionController::TestCase
14
- def setup
15
- ActionController::Base.perform_caching = true
16
- @store = ActiveSupport::Cache::MemoryStore.new
17
- ActionController::Base.cache_store = @store
18
- @controller = FragmentCachingTestController.new
19
- @params = {:controller => 'posts', :action => 'index'}
20
- @request = ActionController::TestRequest.new
21
- @response = ActionController::TestResponse.new
22
- @controller.params = @params
23
- @controller.request = @request
24
- @controller.response = @response
25
- @controller.send(:initialize_current_url)
26
- @controller.send(:initialize_template_class, @response)
27
- @controller.send(:assign_shortcuts, @request, @response)
28
- end
29
-
30
- def test_html_safety
31
- assert_nil @store.read('views/name')
32
- content = 'value'.html_safe
33
- assert_equal content, @controller.write_fragment('name', content)
34
-
35
- cached = @store.read('views/name')
36
- assert_equal content, cached
37
- assert_equal String, cached.class
38
-
39
- html_safe = @controller.read_fragment('name')
40
- assert_equal content, html_safe
41
- assert html_safe.html_safe?
42
- end
43
- end
@@ -1,29 +0,0 @@
1
- require 'test_helper'
2
-
3
- class DateHelperTest < ActionView::TestCase
4
- silence_warnings do
5
- Post = Struct.new("Post", :id, :written_on, :updated_at)
6
- end
7
-
8
- def test_select_html_safety
9
- assert select_day(16).html_safe?
10
- assert select_month(8).html_safe?
11
- assert select_year(Time.mktime(2003, 8, 16, 8, 4, 18)).html_safe?
12
- assert select_minute(Time.mktime(2003, 8, 16, 8, 4, 18)).html_safe?
13
- assert select_second(Time.mktime(2003, 8, 16, 8, 4, 18)).html_safe?
14
-
15
- assert select_minute(8, :use_hidden => true).html_safe?
16
- assert select_month(8, :prompt => 'Choose month').html_safe?
17
-
18
- assert select_time(Time.mktime(2003, 8, 16, 8, 4, 18), {}, :class => 'selector').html_safe?
19
- assert select_date(Time.mktime(2003, 8, 16), :date_separator => " / ", :start_year => 2003, :end_year => 2005, :prefix => "date[first]").html_safe?
20
- end
21
-
22
- def test_object_select_html_safety
23
- @post = Post.new
24
- @post.written_on = Date.new(2004, 6, 15)
25
-
26
- assert date_select("post", "written_on", :default => Time.local(2006, 9, 19, 15, 16, 35), :include_blank => true).html_safe?
27
- assert time_select("post", "written_on", :ignore_date => true).html_safe?
28
- end
29
- end
@@ -1,112 +0,0 @@
1
- require 'test_helper'
2
-
3
- class DeprecatedOutputSafetyTest < ActiveSupport::TestCase
4
- def setup
5
- @string = "hello"
6
- end
7
-
8
- test "A string can be marked safe using html_safe!" do
9
- assert_deprecated do
10
- @string.html_safe!
11
- assert @string.html_safe?
12
- end
13
- end
14
-
15
- test "Marking a string safe returns the string using html_safe!" do
16
- assert_deprecated do
17
- assert_equal @string, @string.html_safe!
18
- end
19
- end
20
-
21
- test "Adding a safe string to another safe string returns a safe string using html_safe!" do
22
- assert_deprecated do
23
- @other_string = "other".html_safe!
24
- @string.html_safe!
25
- @combination = @other_string + @string
26
-
27
- assert_equal "otherhello", @combination
28
- assert @combination.html_safe?
29
- end
30
- end
31
-
32
- test "Adding an unsafe string to a safe string returns an unsafe string using html_safe!" do
33
- assert_deprecated do
34
- @other_string = "other".html_safe!
35
- @combination = @other_string + "<foo>"
36
- @other_combination = @string + "<foo>"
37
-
38
- assert_equal "other<foo>", @combination
39
- assert_equal "hello<foo>", @other_combination
40
-
41
- assert !@combination.html_safe?
42
- assert !@other_combination.html_safe?
43
- end
44
- end
45
-
46
- test "Concatting safe onto unsafe yields unsafe using html_safe!" do
47
- assert_deprecated do
48
- @other_string = "other"
49
- @string.html_safe!
50
-
51
- @other_string.concat(@string)
52
- assert !@other_string.html_safe?
53
- end
54
- end
55
-
56
- test "Concatting unsafe onto safe yields unsafe using html_safe!" do
57
- assert_deprecated do
58
- @other_string = "other".html_safe!
59
- string = @other_string.concat("<foo>")
60
- assert_equal "other<foo>", string
61
- assert !string.html_safe?
62
- end
63
- end
64
-
65
- test "Concatting safe onto safe yields safe using html_safe!" do
66
- assert_deprecated do
67
- @other_string = "other".html_safe!
68
- @string.html_safe!
69
-
70
- @other_string.concat(@string)
71
- assert @other_string.html_safe?
72
- end
73
- end
74
-
75
- test "Concatting safe onto unsafe with << yields unsafe using html_safe!" do
76
- assert_deprecated do
77
- @other_string = "other"
78
- @string.html_safe!
79
-
80
- @other_string << @string
81
- assert !@other_string.html_safe?
82
- end
83
- end
84
-
85
- test "Concatting unsafe onto safe with << yields unsafe using html_safe!" do
86
- assert_deprecated do
87
- @other_string = "other".html_safe!
88
- string = @other_string << "<foo>"
89
- assert_equal "other<foo>", string
90
- assert !string.html_safe?
91
- end
92
- end
93
-
94
- test "Concatting safe onto safe with << yields safe using html_safe!" do
95
- assert_deprecated do
96
- @other_string = "other".html_safe!
97
- @string.html_safe!
98
-
99
- @other_string << @string
100
- assert @other_string.html_safe?
101
- end
102
- end
103
-
104
- test "Concatting a fixnum to safe always yields safe using html_safe!" do
105
- assert_deprecated do
106
- @string.html_safe!
107
- @string.concat(13)
108
- assert_equal "hello".concat(13), @string
109
- assert @string.html_safe?
110
- end
111
- end
112
- end
@@ -1,36 +0,0 @@
1
- require 'test_helper'
2
-
3
- class ErbUtilTest < Test::Unit::TestCase
4
- include ERB::Util
5
-
6
- ERB::Util::HTML_ESCAPE.each do |given, expected|
7
- define_method "test_html_escape_#{expected.gsub(/\W/, '')}" do
8
- assert_equal expected, html_escape(given)
9
- end
10
-
11
- unless given == '"'
12
- define_method "test_json_escape_#{expected.gsub(/\W/, '')}" do
13
- assert_equal ERB::Util::JSON_ESCAPE[given], json_escape(given)
14
- end
15
- end
16
- end
17
-
18
- def test_html_escape_is_html_safe
19
- escaped = h("<p>")
20
- assert_equal "&lt;p&gt;", escaped
21
- assert escaped.html_safe?
22
- end
23
-
24
- def test_html_escape_passes_html_escpe_unmodified
25
- escaped = h("<p>".html_safe)
26
- assert_equal "<p>", escaped
27
- assert escaped.html_safe?
28
- end
29
-
30
- def test_rest_in_ascii
31
- (0..127).to_a.map {|int| int.chr }.each do |chr|
32
- next if %w(& " < >).include?(chr)
33
- assert_equal chr, html_escape(chr)
34
- end
35
- end
36
- end