haml 3.1.0.alpha.2 → 3.1.0.alpha.5

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of haml might be problematic. Click here for more details.

@@ -1 +1 @@
1
- 3.1.0.alpha.2
1
+ 3.1.0.alpha.5
data/VERSION CHANGED
@@ -1 +1 @@
1
- 3.1.0.alpha.2
1
+ 3.1.0.alpha.5
@@ -190,7 +190,7 @@ module Haml
190
190
  ensure
191
191
  # Get rid of the current buffer
192
192
  scope_object.instance_eval do
193
- @haml_buffer = buffer.upper
193
+ @haml_buffer = buffer.upper if buffer
194
194
  end
195
195
  end
196
196
  alias_method :to_html, :render
@@ -118,8 +118,8 @@ END
118
118
 
119
119
  names.map do |name|
120
120
  # Can't use || because someone might explicitly pass in false with a symbol
121
- sym_local = "_haml_locals[#{name.to_sym.inspect}]"
122
- str_local = "_haml_locals[#{name.to_s.inspect}]"
121
+ sym_local = "_haml_locals[#{inspect(name.to_sym)}]"
122
+ str_local = "_haml_locals[#{inspect(name.to_s)}]"
123
123
  "#{name} = #{sym_local}.nil? ? #{str_local} : #{sym_local}"
124
124
  end.join(';') + ';'
125
125
  end
@@ -320,7 +320,7 @@ END
320
320
  @to_merge.each do |type, val, tabs|
321
321
  case type
322
322
  when :text
323
- str << val.inspect[1...-1]
323
+ str << inspect(val)[1...-1]
324
324
  mtabs += tabs
325
325
  when :script
326
326
  if mtabs != 0 && !@options[:ugly]
@@ -660,7 +660,7 @@ END
660
660
  if type == :static
661
661
  static_attributes[name] = val
662
662
  else
663
- dynamic_attributes << name.inspect << " => " << val << ","
663
+ dynamic_attributes << inspect(name) << " => " << val << ","
664
664
  end
665
665
  end
666
666
  dynamic_attributes << "}"
@@ -695,7 +695,7 @@ END
695
695
 
696
696
  return name, [:static, content.first[1]] if content.size == 1
697
697
  return name, [:dynamic,
698
- '"' + content.map {|(t, v)| t == :str ? v.inspect[1...-1] : "\#{#{v}}"}.join + '"']
698
+ '"' + content.map {|(t, v)| t == :str ? inspect(v)[1...-1] : "\#{#{v}}"}.join + '"']
699
699
  end
700
700
 
701
701
  # Parses a line that will render as an XHTML tag, and adds the code that will
@@ -800,7 +800,7 @@ END
800
800
  return if tag_closed
801
801
  else
802
802
  flush_merged_text
803
- content = parse ? 'nil' : value.inspect
803
+ content = parse ? 'nil' : inspect(value)
804
804
  if attributes_hashes.empty?
805
805
  attributes_hashes = ''
806
806
  elsif attributes_hashes.size == 1
@@ -811,7 +811,7 @@ END
811
811
 
812
812
  args = [tag_name, self_closing, !block_opened?, preserve_tag, escape_html,
813
813
  attributes, nuke_outer_whitespace, nuke_inner_whitespace
814
- ].map { |v| v.inspect }.join(', ')
814
+ ].map {|v| inspect(v)}.join(', ')
815
815
  push_silent "_hamlout.open_tag(#{args}, #{object_ref}, #{content}#{attributes_hashes})"
816
816
  @dont_tab_up_next_text = @dont_indent_next_line = dont_indent_next_line
817
817
  end
@@ -1017,14 +1017,14 @@ END
1017
1017
 
1018
1018
  def unescape_interpolation(str, opts = {})
1019
1019
  res = ''
1020
- rest = Haml::Shared.handle_interpolation str.dump do |scan|
1020
+ rest = Haml::Shared.handle_interpolation inspect(str) do |scan|
1021
1021
  escapes = (scan[2].size - 1) / 2
1022
1022
  res << scan.matched[0...-3 - escapes]
1023
1023
  if escapes % 2 == 1
1024
1024
  res << '#{'
1025
1025
  else
1026
1026
  content = eval('"' + balance(scan, ?{, ?}, 1)[0][0...-1] + '"')
1027
- content = "Haml::Helpers.html_escape(#{content})" if opts[:escape_html]
1027
+ content = "Haml::Helpers.html_escape((#{content}))" if opts[:escape_html]
1028
1028
  res << '#{' + content + "}"# Use eval to get rid of string escapes
1029
1029
  end
1030
1030
  end
@@ -32,7 +32,7 @@ module Haml
32
32
  # @param arr [Array<(Object, Object)>] An array of pairs
33
33
  # @return [Hash] A hash
34
34
  def to_hash(arr)
35
- arr.compact.inject({}) {|h, (k, v)| h[k] = v; h}
35
+ Hash[arr.compact]
36
36
  end
37
37
 
38
38
  # Maps the keys in a hash according to a block.
@@ -670,6 +670,19 @@ MSG
670
670
  set1.to_a.uniq.sort_by {|e| e.hash}.eql?(set2.to_a.uniq.sort_by {|e| e.hash})
671
671
  end
672
672
 
673
+ # Like `Object#inspect`, but preserves non-ASCII characters rather than escaping them under Ruby 1.9.2.
674
+ # This is necessary so that the precompiled Haml template can be `#encode`d into `@options[:encoding]`
675
+ # before being evaluated.
676
+ #
677
+ # @param obj {Object}
678
+ # @return {String}
679
+ def inspect(obj)
680
+ return obj.inspect unless version_geq(::RUBY_VERSION, "1.9.2")
681
+ return ':' + inspect(obj.to_s) if obj.is_a?(Symbol)
682
+ return obj.inspect unless obj.is_a?(String)
683
+ '"' + obj.gsub(/[\x00-\x7F]+/) {|s| s.inspect[1...-1]} + '"'
684
+ end
685
+
673
686
  ## Static Method Stuff
674
687
 
675
688
  # The context in which the ERB for \{#def\_static\_method} will be run.
@@ -111,6 +111,17 @@ MESSAGE
111
111
  Haml::Engine.new(text, options)
112
112
  end
113
113
 
114
+ def setup
115
+ return if Haml::Util.ruby1_8?
116
+ @old_default_internal = Encoding.default_internal
117
+ Encoding.default_internal = nil
118
+ end
119
+
120
+ def teardown
121
+ return if Haml::Util.ruby1_8?
122
+ Encoding.default_internal = @old_default_internal
123
+ end
124
+
114
125
  def test_empty_render
115
126
  assert_equal "", render("")
116
127
  end
@@ -763,6 +774,14 @@ HTML
763
774
  HAML
764
775
  end
765
776
 
777
+ def test_escape_html_with_interpolated_if_statement
778
+ assert_equal(<<HTML, render(<<HAML, :escape_html => true))
779
+ foo,
780
+ HTML
781
+ foo\#{"," if true}
782
+ HAML
783
+ end
784
+
766
785
  # HTML escaping tests
767
786
 
768
787
  def test_ampersand_equals_should_escape
@@ -1506,7 +1525,7 @@ HAML
1506
1525
 
1507
1526
  def test_loud_ruby_multiline_with_block
1508
1527
  assert_equal(<<HTML, render(<<HAML))
1509
- farfazfang
1528
+ #{%w[far faz fang]}
1510
1529
  <p>foo</p>
1511
1530
  <p>bar</p>
1512
1531
  HTML
@@ -1636,18 +1655,8 @@ HAML
1636
1655
  HAML
1637
1656
  end
1638
1657
 
1639
- def test_convert_template_render
1640
- assert_equal(<<HTML, render(<<HAML.encode("iso-8859-1"), :encoding => "utf-8"))
1641
- <p>bâr</p>
1642
- <p>föö</p>
1643
- HTML
1644
- %p bâr
1645
- %p föö
1646
- HAML
1647
- end
1648
-
1649
1658
  def test_fake_ascii_encoding
1650
- assert_equal(<<HTML.force_encoding("ascii-8bit"), render(<<HAML, :encoding => "ascii-8bit"))
1659
+ assert_encoded_equal(<<HTML.force_encoding("ascii-8bit"), render(<<HAML, :encoding => "ascii-8bit"))
1651
1660
  <p>bâr</p>
1652
1661
  <p>föö</p>
1653
1662
  HTML
@@ -1701,15 +1710,23 @@ HTML
1701
1710
  HAML
1702
1711
  end
1703
1712
 
1704
- def test_different_coding_comment_than_encoding
1705
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1706
- <p>bâr</p>
1707
- <p>föö</p>
1708
- HTML
1709
- -# coding: ibm866
1710
- %p bâr
1711
- %p föö
1712
- HAML
1713
+ def test_coding_comments
1714
+ assert_valid_encoding_comment("-# coding: ibm866")
1715
+ assert_valid_encoding_comment("-# CodINg: IbM866")
1716
+ assert_valid_encoding_comment("-#coding:ibm866")
1717
+ assert_valid_encoding_comment("-# CodINg= ibm866")
1718
+ assert_valid_encoding_comment("-# foo BAR FAOJcoding: ibm866")
1719
+ assert_valid_encoding_comment("-# coding: ibm866 ASFJ (&(&#!$")
1720
+ assert_valid_encoding_comment("-# -*- coding: ibm866")
1721
+ assert_valid_encoding_comment("-# coding: ibm866 -*- coding: blah")
1722
+ assert_valid_encoding_comment("-# -*- coding: ibm866 -*-")
1723
+ assert_valid_encoding_comment("-# -*- encoding: ibm866 -*-")
1724
+ assert_valid_encoding_comment('-# -*- coding: "ibm866" -*-')
1725
+ assert_valid_encoding_comment("-#-*-coding:ibm866-*-")
1726
+ assert_valid_encoding_comment("-#-*-coding:ibm866-*-")
1727
+ assert_valid_encoding_comment("-# -*- foo: bar; coding: ibm866; baz: bang -*-")
1728
+ assert_valid_encoding_comment("-# foo bar coding: baz -*- coding: ibm866 -*-")
1729
+ assert_valid_encoding_comment("-# -*- coding: ibm866 -*- foo bar coding: baz")
1713
1730
  end
1714
1731
 
1715
1732
  def test_different_coding_than_system
@@ -1719,182 +1736,27 @@ HTML
1719
1736
  %p тАЬ
1720
1737
  HAML
1721
1738
  end
1739
+ end
1722
1740
 
1723
- def test_case_insensitive_coding_comment
1724
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1725
- <p>bâr</p>
1726
- <p>föö</p>
1727
- HTML
1728
- -# CodINg: IbM866
1729
- %p bâr
1730
- %p föö
1731
- HAML
1732
- end
1733
-
1734
- def test_whitespace_insensitive_coding_comment
1735
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1736
- <p>bâr</p>
1737
- <p>föö</p>
1738
- HTML
1739
- -#coding:ibm866
1740
- %p bâr
1741
- %p föö
1742
- HAML
1743
- end
1744
-
1745
- def test_equals_coding_comment
1746
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1747
- <p>bâr</p>
1748
- <p>föö</p>
1749
- HTML
1750
- -# CodINg= ibm866
1751
- %p bâr
1752
- %p föö
1753
- HAML
1754
- end
1755
-
1756
- def test_prefixed_coding_comment
1757
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1758
- <p>bâr</p>
1759
- <p>föö</p>
1760
- HTML
1761
- -# foo BAR FAOJcoding: ibm866
1762
- %p bâr
1763
- %p föö
1764
- HAML
1765
- end
1766
-
1767
- def test_suffixed_coding_comment
1768
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1769
- <p>bâr</p>
1770
- <p>föö</p>
1771
- HTML
1772
- -# coding: ibm866 ASFJ (&(&#!$
1773
- %p bâr
1774
- %p föö
1775
- HAML
1776
- end
1777
-
1778
- def test_emacs_prefixed_coding_comment
1779
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1780
- <p>bâr</p>
1781
- <p>föö</p>
1782
- HTML
1783
- -# -*- coding: ibm866
1784
- %p bâr
1785
- %p föö
1786
- HAML
1787
- end
1788
-
1789
- def test_emacs_suffixed_coding_comment
1790
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1791
- <p>bâr</p>
1792
- <p>föö</p>
1793
- HTML
1794
- -# coding: ibm866 -*- coding: blah
1795
- %p bâr
1796
- %p föö
1797
- HAML
1798
- end
1799
-
1800
- def test_emacs_coding_comment
1801
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1802
- <p>bâr</p>
1803
- <p>föö</p>
1804
- HTML
1805
- -# -*- coding: ibm866 -*-
1806
- %p bâr
1807
- %p föö
1808
- HAML
1809
- end
1810
-
1811
- def test_emacs_encoding_comment
1812
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1813
- <p>bâr</p>
1814
- <p>föö</p>
1815
- HTML
1816
- -# -*- encoding: ibm866 -*-
1817
- %p bâr
1818
- %p föö
1819
- HAML
1820
- end
1821
-
1822
- def test_quoted_emacs_coding_comment
1823
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1824
- <p>bâr</p>
1825
- <p>föö</p>
1826
- HTML
1827
- -# -*- coding: "ibm866" -*-
1828
- %p bâr
1829
- %p föö
1830
- HAML
1831
- end
1832
-
1833
- def test_whitespace_insensitive_emacs_coding_comment
1834
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1835
- <p>bâr</p>
1836
- <p>föö</p>
1837
- HTML
1838
- -#-*-coding:ibm866-*-
1839
- %p bâr
1840
- %p föö
1841
- HAML
1842
- end
1843
-
1844
- def test_whitespace_insensitive_emacs_coding_comment
1845
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1846
- <p>bâr</p>
1847
- <p>föö</p>
1848
- HTML
1849
- -#-*-coding:ibm866-*-
1850
- %p bâr
1851
- %p föö
1852
- HAML
1853
- end
1854
-
1855
- def test_one_of_several_emacs_comments
1856
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1857
- <p>bâr</p>
1858
- <p>föö</p>
1859
- HTML
1860
- -# -*- foo: bar; coding: ibm866; baz: bang -*-
1861
- %p bâr
1862
- %p föö
1863
- HAML
1864
- end
1865
-
1866
- def test_prefixed_emacs_coding_comment
1867
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1868
- <p>bâr</p>
1869
- <p>föö</p>
1870
- HTML
1871
- -# foo bar coding: baz -*- coding: ibm866 -*-
1872
- %p bâr
1873
- %p föö
1874
- HAML
1875
- end
1741
+ private
1876
1742
 
1877
- def test_suffixed_emacs_coding_comment
1878
- assert_renders_encoded(<<HTML.force_encoding("IBM866"), <<HAML)
1879
- <p>bâr</p>
1880
- <p>föö</p>
1743
+ def assert_valid_encoding_comment(comment)
1744
+ assert_renders_encoded(<<HTML.encode("IBM866"), <<HAML.encode("IBM866").force_encoding("UTF-8"))
1745
+ <p>ЖЛЫ</p>
1746
+ <p>тАЬ</p>
1881
1747
  HTML
1882
- -# -*- coding: ibm866 -*- foo bar coding: baz
1883
- %p bâr
1884
- %p föö
1748
+ #{comment}
1749
+ %p ЖЛЫ
1750
+ %p тАЬ
1885
1751
  HAML
1886
- end
1887
-
1888
1752
  end
1889
1753
 
1890
- private
1891
-
1892
1754
  def assert_converts_template_properly
1893
- engine = Haml::Engine.new(<<HAML.encode("iso-8859-1"), :encoding => "utf-8")
1755
+ engine = Haml::Engine.new(<<HAML.encode("iso-8859-1"), :encoding => "macRoman")
1894
1756
  %p bâr
1895
1757
  %p föö
1896
1758
  HAML
1897
- assert_equal(<<HTML, yield(engine))
1759
+ assert_encoded_equal(<<HTML.encode("macRoman"), yield(engine))
1898
1760
  <p>bâr</p>
1899
1761
  <p>föö</p>
1900
1762
  HTML
@@ -1902,7 +1764,11 @@ HTML
1902
1764
 
1903
1765
  def assert_renders_encoded(html, haml)
1904
1766
  result = render(haml)
1905
- assert_equal html.encoding, result.encoding
1906
- assert_equal html, result
1767
+ assert_encoded_equal html, result
1768
+ end
1769
+
1770
+ def assert_encoded_equal(expected, actual)
1771
+ assert_equal expected.encoding, actual.encoding
1772
+ assert_equal expected, actual
1907
1773
  end
1908
1774
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: haml
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0.alpha.2
4
+ version: 3.1.0.alpha.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Weizenbaum
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-09-22 00:00:00 -04:00
13
+ date: 2010-09-29 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency