haml-edge 2.3.62 → 2.3.63

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/EDGE_GEM_VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.62
1
+ 2.3.63
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.62
1
+ 2.3.63
data/lib/haml/engine.rb CHANGED
@@ -179,7 +179,8 @@ module Haml
179
179
  @haml_buffer = buffer
180
180
  end
181
181
 
182
- eval(precompiled, scope, @options[:filename], @options[:line])
182
+ eval(precompiled + "\n" + precompiled_method_return_value,
183
+ scope, @options[:filename], @options[:line])
183
184
 
184
185
  # Get rid of the current buffer
185
186
  scope_object.instance_eval do
@@ -99,11 +99,17 @@ __in_erb_template = true
99
99
  END
100
100
  postamble = <<END.gsub("\n", ";")
101
101
  @haml_buffer = @haml_buffer.upper
102
- _erbout
102
+ #{precompiled_method_return_value}
103
103
  END
104
104
  preamble + locals_code(local_names) + precompiled + postamble
105
105
  end
106
106
 
107
+ # Returns the string used as the return value of the precompiled method.
108
+ # This method exists so it can be monkeypatched to return modified values.
109
+ def precompiled_method_return_value
110
+ "_erbout"
111
+ end
112
+
107
113
  def locals_code(names)
108
114
  names = names.keys if Hash == names
109
115
 
data/lib/haml/template.rb CHANGED
@@ -11,6 +11,31 @@ module Haml
11
11
  #
12
12
  # @return [Hash<Symbol, Object>]
13
13
  attr_accessor :options
14
+
15
+ # Enables integration with the Rails 2.2.5+ XSS protection,
16
+ # if it's available and enabled.
17
+ #
18
+ # @return [Boolean] Whether the XSS integration was enabled.
19
+ def try_enabling_xss_integration
20
+ return false unless ActionView::Base.respond_to?(:xss_safe?) && ActionView::Base.xss_safe?
21
+
22
+ Haml::Template.options[:escape_html] = true
23
+
24
+ Haml::Util.module_eval {def rails_xss_safe?; true; end}
25
+
26
+ require 'haml/helpers/xss_mods'
27
+ Haml::Helpers.send(:include, Haml::Helpers::XssMods)
28
+
29
+ Haml::Precompiler.module_eval do
30
+ def precompiled_method_return_value_with_haml_xss
31
+ "(#{precompiled_method_return_value_without_haml_xss}).html_safe!"
32
+ end
33
+ alias_method :precompiled_method_return_value_without_haml_xss, :precompiled_method_return_value
34
+ alias_method :precompiled_method_return_value, :precompiled_method_return_value_with_haml_xss
35
+ end
36
+
37
+ true
38
+ end
14
39
  end
15
40
  end
16
41
 
@@ -27,19 +52,13 @@ else
27
52
  require 'haml/template/patch'
28
53
  end
29
54
 
30
- if ActionView::Base.respond_to?(:xss_safe?) && ActionView::Base.xss_safe?
31
- Haml::Template.options[:escape_html] = true
32
-
33
- module Haml::Util
34
- def rails_xss_safe?
35
- true
36
- end
37
- end
38
-
39
- require 'haml/helpers/xss_mods'
40
- module Haml::Helpers
41
- include XssMods
42
- end
55
+ # Enable XSS integration. Use Rails' after_initialize method if possible
56
+ # so that integration will be checked after the rails_xss plugin is loaded
57
+ # (for Rails 2.3.* where it's not enabled by default).
58
+ if defined?(Rails.configuration.after_initialize)
59
+ Rails.configuration.after_initialize {Haml::Template.try_enabling_xss_integration}
60
+ else
61
+ Haml::Template.try_enabling_xss_integration
43
62
  end
44
63
 
45
64
  if defined?(RAILS_ROOT)
@@ -241,6 +241,9 @@ END
241
241
 
242
242
  ## XSS Protection Tests
243
243
 
244
+ # In order to enable these, either test against Rails 3.0
245
+ # or test against Rails 2.2.5+ with the rails_xss plugin
246
+ # (http://github.com/NZKoz/rails_xss) in test/plugins.
244
247
  if Haml::Util.rails_xss_safe?
245
248
  def test_escape_html_option_set
246
249
  assert Haml::Template.options[:escape_html]
@@ -273,5 +276,13 @@ END
273
276
  def test_xss_protection_with_mixed_strings_in_interpolation
274
277
  assert_equal("Foo & Bar &amp; Baz\n", render('Foo #{"&".html_safe!} Bar #{"&"} Baz', :action_view))
275
278
  end
279
+
280
+ def test_rendered_string_is_html_safe
281
+ assert(render("Foo").html_safe?)
282
+ end
283
+
284
+ def test_rendered_string_is_html_safe_with_action_view
285
+ assert(render("Foo", :action_view).html_safe?)
286
+ end
276
287
  end
277
288
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml-edge
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.62
4
+ version: 2.3.63
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Weizenbaum