haml-edge 2.1.19 → 2.1.20

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.1.19
1
+ 2.1.20
data/VERSION CHANGED
@@ -1 +1 @@
1
- 2.1.19
1
+ 2.1.20
@@ -83,7 +83,7 @@ module Haml
83
83
  DOCTYPE_REGEX = /(\d\.\d)?[\s]*([a-z]*)/i
84
84
 
85
85
  # The Regex that matches a literal string or symbol value
86
- LITERAL_VALUE_REGEX = /^\s*(:(\w*)|(('|")([^\\\#'"]*?)\4))\s*$/
86
+ LITERAL_VALUE_REGEX = /:(\w*)|(["'])([^\\#'"]|\\.)*\2/
87
87
 
88
88
  private
89
89
 
@@ -453,29 +453,18 @@ END
453
453
  attributes
454
454
  end
455
455
 
456
- def parse_literal_value(text)
457
- return nil unless text
458
- text.match(LITERAL_VALUE_REGEX)
459
-
460
- # $2 holds the value matched by a symbol, but is nil for a string match
461
- # $5 holds the value matched by a string
462
- $2 || $5
463
- end
464
-
465
456
  def parse_static_hash(text)
466
457
  return {} unless text
467
458
 
468
459
  attributes = {}
469
- text.split(',').each do |attrib|
470
- key, value, more = attrib.split('=>')
471
-
472
- # Make sure the key and value and only the key and value exist
473
- # Otherwise, it's too complicated or dynamic and we'll defer it to the actual Ruby parser
474
- key = parse_literal_value key
475
- value = parse_literal_value value
476
- return nil if more || key.nil? || value.nil?
477
-
478
- attributes[key] = value
460
+ scanner = StringScanner.new(text)
461
+ scanner.scan(/\s+/)
462
+ until scanner.eos?
463
+ return unless key = scanner.scan(LITERAL_VALUE_REGEX)
464
+ return unless scanner.scan(/\s*=>\s*/)
465
+ return unless value = scanner.scan(LITERAL_VALUE_REGEX)
466
+ attributes[eval(key).to_s] = eval(value).to_s
467
+ scanner.scan(/[,\s]*/)
479
468
  end
480
469
  text.count("\n").times { newline }
481
470
  attributes
@@ -756,6 +756,13 @@ END
756
756
  assert_raise(Haml::Error, "Invalid output format :html1") { engine("%br", :format => :html1) }
757
757
  end
758
758
 
759
+ def test_static_hashes
760
+ assert_equal("<a b='a =&gt; b'></a>\n", render("%a{:b => 'a => b'}", :suppress_eval => true))
761
+ assert_equal("<a b='a, b'></a>\n", render("%a{:b => 'a, b'}", :suppress_eval => true))
762
+ assert_equal("<a b='a\tb'></a>\n", render('%a{:b => "a\tb"}', :suppress_eval => true))
763
+ assert_equal("<a b='a\#{foo}b'></a>\n", render('%a{:b => "a\\#{foo}b"}', :suppress_eval => true))
764
+ end
765
+
759
766
  # HTML 4.0
760
767
 
761
768
  def test_html_has_no_self_closing_tags
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.1.19
4
+ version: 2.1.20
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Weizenbaum