mirror of
https://github.com/haml/haml.git
synced 2022-11-09 12:33:31 -05:00
[Haml] Don't print errors for #escape_once under 1.9.
This commit is contained in:
parent
4f67e2427d
commit
90fb7c3066
6 changed files with 36 additions and 6 deletions
|
@ -3,6 +3,11 @@
|
|||
* Table of contents
|
||||
{:toc}
|
||||
|
||||
## 2.2.14
|
||||
|
||||
* Don't print warnings when escaping attributes containing non-ASCII characters
|
||||
in Ruby 1.9.
|
||||
|
||||
## [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"`}
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
require 'erb'
|
||||
require 'set'
|
||||
require 'enumerator'
|
||||
require 'stringio'
|
||||
|
||||
module Haml
|
||||
# A module containing various useful functions.
|
||||
|
@ -122,6 +123,16 @@ module Haml
|
|||
end
|
||||
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,
|
||||
|
|
|
@ -1033,6 +1033,11 @@ END
|
|||
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
|
||||
|
|
|
@ -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))
|
||||
|
|
|
@ -29,10 +29,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
|
||||
|
|
Loading…
Add table
Reference in a new issue