Merge commit 'origin/master'

This commit is contained in:
Nathan Weizenbaum 2009-11-11 18:20:08 -08:00
commit a9a7dace90
9 changed files with 50 additions and 12 deletions

View File

@ -319,11 +319,11 @@ rescue LoadError; end
# ----- Testing Multiple Rails Versions -----
rails_versions = [
"v2.3.0",
"v2.3.4",
"v2.2.2",
"v2.1.2",
"v2.0.5"
]
rails_versions << "v2.0.5" if RUBY_VERSION =~ /^1\.8/
namespace :test do
desc "Test all supported versions of rails. This takes a while."

View File

@ -128,6 +128,13 @@ that surrounds the filtered text with `<style>` and CDATA tags.
* Multi-line ERB statements are now properly indented,
and those without any content are removed.
## 2.2.14
* Don't print warnings when escaping attributes containing non-ASCII characters
in Ruby 1.9.
* Don't crash when parsing an XHTML Strict doctype in `html2haml`.
## [2.2.13](http://github.com/nex3/haml/commit/2.2.13)
* Allow users to specify {file:HAML_REFERENCE.md#encoding_option `:encoding => "ascii-8bit"`}

View File

@ -483,7 +483,9 @@ END
# @param text [String] The string to sanitize
# @return [String] The sanitized string
def escape_once(text)
text.to_s.gsub(/[\"><]|&(?!(?:[a-zA-Z]+|(#\d+));)/n) {|s| HTML_ESCAPE[s]}
Haml::Util.silence_warnings do
text.to_s.gsub(/[\"><]|&(?!(?:[a-zA-Z]+|(#\d+));)/n) {|s| HTML_ESCAPE[s]}
end
end
# Returns whether or not the current template is a Haml template.

View File

@ -195,10 +195,7 @@ module Haml
end
version = " #{version}" if version
if strictness
strictness[0] = strictness[0] - 32
strictness = " #{strictness}"
end
strictness = " #{strictness.capitalize}" if strictness
"#{tabulate(tabs)}!!!#{version}#{strictness}\n"
end

View File

@ -1,6 +1,7 @@
require 'erb'
require 'set'
require 'enumerator'
require 'stringio'
module Haml
# A module containing various useful functions.
@ -133,6 +134,16 @@ module Haml
info
end
# Silence all output to STDERR within a block.
#
# @yield A block in which no output will be printed to STDERR
def silence_warnings
the_real_stderr, $stderr = $stderr, StringIO.new
yield
ensure
$stderr = the_real_stderr
end
## Cross Rails Version Compatibility
# Returns the root of the Rails application,

View File

@ -1059,6 +1059,11 @@ SASS
assert_equal("<a></a>\n", render('%a{:b => "a #{1 + 1} b", :c => "d"}', :suppress_eval => true))
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')"))
end
# HTML 4.0
def test_html_has_no_self_closing_tags

View File

@ -262,6 +262,15 @@ HTML
end
end
# Regression Tests
def test_xhtml_strict_doctype
assert_equal('!!! Strict', render(<<HTML))
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
HTML
end
protected
def render(text, options = {})

View File

@ -59,6 +59,16 @@ class UtilTest < Test::Unit::TestCase
merge_adjacent_strings(["foo ", "bar ", "baz", :bang, "biz", " bop", 12]))
end
def test_silence_warnings
old_stderr, $stderr = $stderr, StringIO.new
warn "Out"
assert_equal("Out\n", $stderr.string)
silence_warnings {warn "In"}
assert_equal("Out\n", $stderr.string)
ensure
$stderr = old_stderr
end
def test_has
assert(has?(:instance_method, String, :chomp!))
assert(has?(:private_instance_method, Haml::Engine, :set_locals))

View File

@ -30,10 +30,7 @@ class Test::Unit::TestCase
$stderr = the_real_stderr
end
def silence_warnings
the_real_stderr, $stderr = $stderr, StringIO.new
yield
ensure
$stderr = the_real_stderr
def silence_warnings(&block)
Haml::Util.silence_warnings(&block)
end
end