mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Allow literal '#' with suppress_eval
Improve the regex that detects whether an attribute value can be treated as a literal to allow lone '#' characters. Explicitly check for '#{', '#@' and '#$'. Fixes #713
This commit is contained in:
parent
ccfcd6497f
commit
09d14bcbef
2 changed files with 15 additions and 2 deletions
|
@ -83,8 +83,7 @@ module Haml
|
|||
DOCTYPE_REGEX = /(\d(?:\.\d)?)?\s*([a-z]*)\s*([^ ]+)?/i
|
||||
|
||||
# The Regex that matches a literal string or symbol value
|
||||
LITERAL_VALUE_REGEX = /:(\w*)|(["'])((?![\\#]|\2).|\\.)*\2/
|
||||
|
||||
LITERAL_VALUE_REGEX = /:(\w*)|(["'])((?!\\|\#{|\#@|\#\$|\2).|\\.)*\2/
|
||||
|
||||
def initialize(template, options)
|
||||
@options = options
|
||||
|
|
|
@ -1386,12 +1386,26 @@ HAML
|
|||
assert_equal("<a b='a, b'></a>\n", render("%a{:b => 'a, b'}", :suppress_eval => true))
|
||||
assert_equal("<a b='a\tb'></a>\n", render('%a{:b => "a\tb"}', :suppress_eval => true))
|
||||
assert_equal("<a b='a\#{foo}b'></a>\n", render('%a{:b => "a\\#{foo}b"}', :suppress_eval => true))
|
||||
assert_equal("<a b='#f00'></a>\n", render("%a{:b => '#f00'}", :suppress_eval => true))
|
||||
end
|
||||
|
||||
def test_dynamic_hashes_with_suppress_eval
|
||||
assert_equal("<a></a>\n", render('%a{:b => "a #{1 + 1} b", :c => "d"}', :suppress_eval => true))
|
||||
end
|
||||
|
||||
def test_interpolates_instance_vars_in_attribute_values
|
||||
scope = Object.new
|
||||
scope.instance_variable_set :@foo, 'bar'
|
||||
assert_equal("<a b='a bar b'></a>\n", render('%a{:b => "a #@foo b"}', :scope => scope))
|
||||
end
|
||||
|
||||
def test_interpolates_global_vars_in_attribute_values
|
||||
# make sure the value isn't just interpolated in during template compilation
|
||||
engine = Haml::Engine.new('%a{:b => "a #$global_var_for_testing b"}')
|
||||
$global_var_for_testing = 'bar'
|
||||
assert_equal("<a b='a bar b'></a>\n", engine.to_html)
|
||||
end
|
||||
|
||||
def test_utf8_attrs
|
||||
assert_equal("<a href='héllo'></a>\n", render("%a{:href => 'héllo'}"))
|
||||
assert_equal("<a href='héllo'></a>\n", render("%a(href='héllo')"))
|
||||
|
|
Loading…
Add table
Reference in a new issue