haml-edge 2.3.50 → 2.3.51

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.50
1
+ 2.3.51
data/Rakefile CHANGED
@@ -22,6 +22,7 @@ Rake::TestTask.new do |t|
22
22
  t.libs << 'lib'
23
23
  test_files = FileList['test/**/*_test.rb']
24
24
  test_files.exclude('test/rails/*')
25
+ test_files.exclude('test/plugins/*')
25
26
  test_files.exclude('test/haml/spec/*')
26
27
  t.test_files = test_files
27
28
  t.verbose = true
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.3.50
1
+ 2.3.51
data/lib/haml/helpers.rb CHANGED
@@ -113,9 +113,7 @@ MESSAGE
113
113
  # @yield The block within which to escape newlines
114
114
  def find_and_preserve(input = nil, tags = haml_buffer.options[:preserve], &block)
115
115
  return find_and_preserve(capture_haml(&block), input || tags) if block
116
-
117
- input = input.to_s
118
- input.gsub(/<(#{tags.map(&Regexp.method(:escape)).join('|')})([^>]*)>(.*?)(<\/\1>)/im) do
116
+ input.to_s.gsub(/<(#{tags.map(&Regexp.method(:escape)).join('|')})([^>]*)>(.*?)(<\/\1>)/im) do
119
117
  "<#{$1}#{$2}>#{preserve($3)}</#{$1}>"
120
118
  end
121
119
  end
@@ -132,10 +130,9 @@ MESSAGE
132
130
  # Escapes newlines within a block of Haml code.
133
131
  #
134
132
  # @yield The block within which to escape newlines
135
- def preserve(input = '', &block)
133
+ def preserve(input = nil, &block)
136
134
  return preserve(capture_haml(&block)) if block
137
-
138
- input.chomp("\n").gsub(/\n/, '&#x000A;').gsub(/\r/, '')
135
+ input.to_s.chomp("\n").gsub(/\n/, '&#x000A;').gsub(/\r/, '')
139
136
  end
140
137
  alias_method :flatten, :preserve
141
138
 
@@ -329,7 +329,10 @@ END
329
329
  end
330
330
 
331
331
  if contains_interpolation?(text)
332
- push_script unescape_interpolation(text), :escape_html => options[:escape_html]
332
+ options[:escape_html] = self.options[:escape_html] if options[:escape_html].nil?
333
+ push_script(
334
+ unescape_interpolation(text, :escape_html => options[:escape_html]),
335
+ :escape_html => false)
333
336
  else
334
337
  push_text text
335
338
  end
@@ -665,30 +668,37 @@ END
665
668
  nuke_inner_whitespace ||= preserve_tag
666
669
  preserve_tag &&= !options[:ugly]
667
670
 
671
+ escape_html = (action == '&' || (action != '!' && @options[:escape_html]))
672
+
668
673
  case action
669
674
  when '/'; self_closing = true
670
675
  when '~'; parse = preserve_script = true
671
676
  when '='
672
677
  parse = true
673
- value = unescape_interpolation(value[1..-1].strip) if value[0] == ?=
678
+ if value[0] == ?=
679
+ value = unescape_interpolation(value[1..-1].strip, :escape_html => escape_html)
680
+ escape_html = false
681
+ end
674
682
  when '&', '!'
675
683
  if value[0] == ?= || value[0] == ?~
676
684
  parse = true
677
685
  preserve_script = (value[0] == ?~)
678
- value =
679
- if value[1] == ?=
680
- unescape_interpolation(value[2..-1].strip)
681
- else
682
- value[1..-1].strip
683
- end
686
+ if value[1] == ?=
687
+ value = unescape_interpolation(value[2..-1].strip, :escape_html => escape_html)
688
+ escape_html = false
689
+ else
690
+ value = value[1..-1].strip
691
+ end
684
692
  elsif contains_interpolation?(value)
693
+ value = unescape_interpolation(value, :escape_html => escape_html)
685
694
  parse = true
686
- value = unescape_interpolation(value)
695
+ escape_html = false
687
696
  end
688
697
  else
689
698
  if contains_interpolation?(value)
699
+ value = unescape_interpolation(value, :escape_html => escape_html)
690
700
  parse = true
691
- value = unescape_interpolation(value)
701
+ escape_html = false
692
702
  end
693
703
  end
694
704
 
@@ -697,8 +707,6 @@ END
697
707
  value = ''
698
708
  end
699
709
 
700
- escape_html = (action == '&' || (action != '!' && @options[:escape_html]))
701
-
702
710
  object_ref = "nil" if object_ref.nil? || @options[:suppress_eval]
703
711
 
704
712
  attributes = parse_class_and_id(attributes)
@@ -936,7 +944,7 @@ END
936
944
  str.include?('#{')
937
945
  end
938
946
 
939
- def unescape_interpolation(str)
947
+ def unescape_interpolation(str, opts = {})
940
948
  res = ''
941
949
  rest = Haml::Shared.handle_interpolation str.dump do |scan|
942
950
  escapes = (scan[2].size - 1) / 2
@@ -944,7 +952,9 @@ END
944
952
  if escapes % 2 == 1
945
953
  res << '#{'
946
954
  else
947
- res << '#{' + eval('"' + balance(scan, ?{, ?}, 1)[0][0...-1] + '"') + "}"# Use eval to get rid of string escapes
955
+ content = eval('"' + balance(scan, ?{, ?}, 1)[0][0...-1] + '"')
956
+ content = "Haml::Helpers.html_escape(#{content})" if opts[:escape_html]
957
+ res << '#{' + content + "}"# Use eval to get rid of string escapes
948
958
  end
949
959
  end
950
960
  res + rest
data/lib/haml/util.rb CHANGED
@@ -122,6 +122,8 @@ module Haml
122
122
  end
123
123
  end
124
124
 
125
+ ## Cross-Ruby-Version Compatibility
126
+
125
127
  # Whether or not this is running under Ruby 1.8 or lower.
126
128
  #
127
129
  # @return [Boolean]
@@ -171,6 +173,8 @@ MSG
171
173
  ruby1_8? ? enum.enum_with_index : enum.each_with_index
172
174
  end
173
175
 
176
+ ## Static Method Stuff
177
+
174
178
  # The context in which the ERB for \{#def\_static\_method} will be run.
175
179
  class StaticConditionalContext
176
180
  # @param set [#include?] The set of variables that are defined for this context.
@@ -168,6 +168,10 @@ class EngineTest < Test::Unit::TestCase
168
168
  assert_equal("<p>\n 2\n</p>\n", render("%p\n \#{1 + 1}"))
169
169
  end
170
170
 
171
+ def test_escaped_interpolation
172
+ assert_equal("<p>Foo &amp; Bar & Baz</p>\n", render('%p& Foo #{"&"} Bar & Baz'))
173
+ end
174
+
171
175
  def test_nil_tag_value_should_render_as_empty
172
176
  assert_equal("<p></p>\n", render("%p= nil"))
173
177
  end
@@ -603,53 +607,53 @@ HAML
603
607
  end
604
608
 
605
609
  def test_string_double_equals_should_be_esaped
606
- assert_equal("<p>4&amp;3</p>\n", render("%p== \#{2+2}&\#{2+1}", :escape_html => true))
607
- assert_equal("<p>4&3</p>\n", render("%p== \#{2+2}&\#{2+1}", :escape_html => false))
610
+ assert_equal("<p>4&&lt;</p>\n", render("%p== \#{2+2}&\#{'<'}", :escape_html => true))
611
+ assert_equal("<p>4&<</p>\n", render("%p== \#{2+2}&\#{'<'}", :escape_html => false))
608
612
  end
609
613
 
610
614
  def test_escaped_inline_string_double_equals
611
- assert_equal("<p>4&amp;3</p>\n", render("%p&== \#{2+2}&\#{2+1}", :escape_html => true))
612
- assert_equal("<p>4&amp;3</p>\n", render("%p&== \#{2+2}&\#{2+1}", :escape_html => false))
615
+ assert_equal("<p>4&&lt;</p>\n", render("%p&== \#{2+2}&\#{'<'}", :escape_html => true))
616
+ assert_equal("<p>4&&lt;</p>\n", render("%p&== \#{2+2}&\#{'<'}", :escape_html => false))
613
617
  end
614
618
 
615
619
  def test_unescaped_inline_string_double_equals
616
- assert_equal("<p>4&3</p>\n", render("%p!== \#{2+2}&\#{2+1}", :escape_html => true))
617
- assert_equal("<p>4&3</p>\n", render("%p!== \#{2+2}&\#{2+1}", :escape_html => false))
620
+ assert_equal("<p>4&<</p>\n", render("%p!== \#{2+2}&\#{'<'}", :escape_html => true))
621
+ assert_equal("<p>4&<</p>\n", render("%p!== \#{2+2}&\#{'<'}", :escape_html => false))
618
622
  end
619
623
 
620
624
  def test_escaped_string_double_equals
621
- assert_equal("<p>\n 4&amp;3\n</p>\n", render("%p\n &== \#{2+2}&\#{2+1}", :escape_html => true))
622
- assert_equal("<p>\n 4&amp;3\n</p>\n", render("%p\n &== \#{2+2}&\#{2+1}", :escape_html => false))
625
+ assert_equal("<p>\n 4&&lt;\n</p>\n", render("%p\n &== \#{2+2}&\#{'<'}", :escape_html => true))
626
+ assert_equal("<p>\n 4&&lt;\n</p>\n", render("%p\n &== \#{2+2}&\#{'<'}", :escape_html => false))
623
627
  end
624
628
 
625
629
  def test_unescaped_string_double_equals
626
- assert_equal("<p>\n 4&3\n</p>\n", render("%p\n !== \#{2+2}&\#{2+1}", :escape_html => true))
627
- assert_equal("<p>\n 4&3\n</p>\n", render("%p\n !== \#{2+2}&\#{2+1}", :escape_html => false))
630
+ assert_equal("<p>\n 4&<\n</p>\n", render("%p\n !== \#{2+2}&\#{'<'}", :escape_html => true))
631
+ assert_equal("<p>\n 4&<\n</p>\n", render("%p\n !== \#{2+2}&\#{'<'}", :escape_html => false))
628
632
  end
629
633
 
630
634
  def test_string_interpolation_should_be_esaped
631
- assert_equal("<p>4&amp;3</p>\n", render("%p \#{2+2}&\#{2+1}", :escape_html => true))
632
- assert_equal("<p>4&3</p>\n", render("%p \#{2+2}&\#{2+1}", :escape_html => false))
635
+ assert_equal("<p>4&&lt;</p>\n", render("%p \#{2+2}&\#{'<'}", :escape_html => true))
636
+ assert_equal("<p>4&<</p>\n", render("%p \#{2+2}&\#{'<'}", :escape_html => false))
633
637
  end
634
638
 
635
639
  def test_escaped_inline_string_interpolation
636
- assert_equal("<p>4&amp;3</p>\n", render("%p& \#{2+2}&\#{2+1}", :escape_html => true))
637
- assert_equal("<p>4&amp;3</p>\n", render("%p& \#{2+2}&\#{2+1}", :escape_html => false))
640
+ assert_equal("<p>4&&lt;</p>\n", render("%p& \#{2+2}&\#{'<'}", :escape_html => true))
641
+ assert_equal("<p>4&&lt;</p>\n", render("%p& \#{2+2}&\#{'<'}", :escape_html => false))
638
642
  end
639
643
 
640
644
  def test_unescaped_inline_string_interpolation
641
- assert_equal("<p>4&3</p>\n", render("%p! \#{2+2}&\#{2+1}", :escape_html => true))
642
- assert_equal("<p>4&3</p>\n", render("%p! \#{2+2}&\#{2+1}", :escape_html => false))
645
+ assert_equal("<p>4&<</p>\n", render("%p! \#{2+2}&\#{'<'}", :escape_html => true))
646
+ assert_equal("<p>4&<</p>\n", render("%p! \#{2+2}&\#{'<'}", :escape_html => false))
643
647
  end
644
648
 
645
649
  def test_escaped_string_interpolation
646
- assert_equal("<p>\n 4&amp;3\n</p>\n", render("%p\n & \#{2+2}&\#{2+1}", :escape_html => true))
647
- assert_equal("<p>\n 4&amp;3\n</p>\n", render("%p\n & \#{2+2}&\#{2+1}", :escape_html => false))
650
+ assert_equal("<p>\n 4&&lt;\n</p>\n", render("%p\n & \#{2+2}&\#{'<'}", :escape_html => true))
651
+ assert_equal("<p>\n 4&&lt;\n</p>\n", render("%p\n & \#{2+2}&\#{'<'}", :escape_html => false))
648
652
  end
649
653
 
650
654
  def test_unescaped_string_interpolation
651
- assert_equal("<p>\n 4&3\n</p>\n", render("%p\n ! \#{2+2}&\#{2+1}", :escape_html => true))
652
- assert_equal("<p>\n 4&3\n</p>\n", render("%p\n ! \#{2+2}&\#{2+1}", :escape_html => false))
655
+ assert_equal("<p>\n 4&<\n</p>\n", render("%p\n ! \#{2+2}&\#{'<'}", :escape_html => true))
656
+ assert_equal("<p>\n 4&<\n</p>\n", render("%p\n ! \#{2+2}&\#{'<'}", :escape_html => false))
653
657
  end
654
658
 
655
659
  def test_scripts_should_respect_escape_html_option
@@ -54,6 +54,11 @@ class UtilTest < Test::Unit::TestCase
54
54
  powerset([1, 2, 3]))
55
55
  end
56
56
 
57
+ def test_merge_adjacent_strings
58
+ assert_equal(["foo bar baz", :bang, "biz bop", 12],
59
+ merge_adjacent_strings(["foo ", "bar ", "baz", :bang, "biz", " bop", 12]))
60
+ end
61
+
57
62
  def test_has
58
63
  assert(has?(:instance_method, String, :chomp!))
59
64
  assert(has?(:private_instance_method, Haml::Engine, :set_locals))
data/test/linked_rails.rb CHANGED
@@ -10,3 +10,13 @@ else
10
10
  end
11
11
  require 'action_controller'
12
12
  require 'action_view'
13
+
14
+ ActionController::Base.logger = Logger.new(nil)
15
+
16
+ # Load plugins from test/plugins.
17
+ # This will only work with very basic plugins,
18
+ # since we don't want to load the entirety of Rails.
19
+ Dir[File.dirname(__FILE__) + '/plugins/*'].each do |plugin|
20
+ $: << plugin + '/lib'
21
+ Object.new.instance_eval(File.read(plugin + '/init.rb'))
22
+ 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.50
4
+ version: 2.3.51
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Weizenbaum