mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
Fixing various edge cases for ==.
git-svn-id: svn://hamptoncatlin.com/haml/trunk@679 7063305b-7217-0410-af8c-cdc13e5119b9
This commit is contained in:
parent
2871354789
commit
890521383d
4 changed files with 40 additions and 8 deletions
|
@ -1,3 +1,5 @@
|
|||
require 'strscan'
|
||||
|
||||
module Haml
|
||||
module Precompiler
|
||||
# Designates an XHTML/XML element.
|
||||
|
@ -609,18 +611,29 @@ END
|
|||
end
|
||||
|
||||
def unescape_interpolation(str)
|
||||
first = str.index(/(^|[^\\])\#\{/)
|
||||
scan = StringScanner.new(str.dump)
|
||||
str = ''
|
||||
|
||||
return str.dump if first.nil?
|
||||
first += 1 unless first == 0
|
||||
while scan.scan(/(.*?)\\\#\{/)
|
||||
str << scan.matched[0...-3]
|
||||
str << eval("\"\\\#{#{balance_brackets(scan)}}\"")
|
||||
end
|
||||
|
||||
last = str.rindex '}'
|
||||
str + scan.rest
|
||||
end
|
||||
|
||||
interpolation = str.slice!(first, last - first)
|
||||
str.insert(first, "_haml_interpolation")
|
||||
def balance_brackets(scanner)
|
||||
str = ''
|
||||
count = 1
|
||||
|
||||
str = str.dump
|
||||
str.gsub("_haml_interpolation", interpolation)
|
||||
while scanner.scan(/(.*?)[\{\}]/)
|
||||
str << scanner.matched
|
||||
count += 1 if scanner.matched[-1] == ?{
|
||||
count -= 1 if scanner.matched[-1] == ?}
|
||||
return str[0...-1] if count == 0
|
||||
end
|
||||
|
||||
raise SyntaxError.new("Unbalanced brackets.")
|
||||
end
|
||||
|
||||
# Counts the tabulation of a line.
|
||||
|
|
|
@ -265,6 +265,12 @@ class EngineTest < Test::Unit::TestCase
|
|||
'"a\nb\n- fee do\nc" doesn\'t produce an exception!')
|
||||
end
|
||||
|
||||
def test_unbalanced_brackets
|
||||
render('== #{1 + 5} foo #{6 + 7 bar #{8 + 9}')
|
||||
rescue Haml::SyntaxError => e
|
||||
assert_equal("Unbalanced brackets.", e.message)
|
||||
end
|
||||
|
||||
def test_no_bluecloth
|
||||
Kernel.module_eval do
|
||||
def gem_original_require_with_bluecloth(file)
|
||||
|
|
|
@ -11,6 +11,12 @@ Embedded? false!
|
|||
Embedded? true!
|
||||
Embedded? true!
|
||||
Embedded? twice! true!
|
||||
Embedded? one af"t"er another!
|
||||
<p>Embedded? false!</p>
|
||||
<p>Embedded? true!</p>
|
||||
<p>Embedded? true!</p>
|
||||
<p>Embedded? twice! true!</p>
|
||||
<p>Embedded? one af"t"er another!</p>
|
||||
<div class='render'><em>wow!</em></div>
|
||||
stuff followed by whitespace
|
||||
<strong>block with whitespace</strong>
|
||||
|
|
|
@ -12,6 +12,13 @@
|
|||
- embedded = true
|
||||
== Embedded? #{embedded}!
|
||||
== Embedded? #{"twice! #{true}"}!
|
||||
== Embedded? #{"one"} af"t"er #{"another"}!
|
||||
%p== Embedded? false!
|
||||
%p== Embedded? #{true}!
|
||||
- embedded = true
|
||||
%p== Embedded? #{embedded}!
|
||||
%p== Embedded? #{"twice! #{true}"}!
|
||||
%p== Embedded? #{"one"} af"t"er #{"another"}!
|
||||
.render= render :inline => "%em= 'wow!'", :type => :haml
|
||||
= "stuff followed by whitespace"
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue