From 5bd2d438a8edd64a45efc85a9305b73ed9e289c9 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sun, 8 Nov 2009 16:45:22 -0800 Subject: [PATCH 1/4] Update tested Rails versions. --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index aa8812f8..d2f671de 100644 --- a/Rakefile +++ b/Rakefile @@ -312,7 +312,7 @@ rescue LoadError; end # ----- Testing Multiple Rails Versions ----- rails_versions = [ - "v2.3.0", + "v2.3.4", "v2.2.2", "v2.1.2", "v2.0.5" From 239252a8b73ad734dd12bef77e58345c6f9661f1 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sun, 8 Nov 2009 16:45:51 -0800 Subject: [PATCH 2/4] Don't test against Rails 2.0.5 under Ruby 1.9. --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index d2f671de..b690b3e4 100644 --- a/Rakefile +++ b/Rakefile @@ -315,8 +315,8 @@ rails_versions = [ "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." From 90fb7c306662a26e07fef2301b11714c28ed6a06 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Wed, 11 Nov 2009 14:30:11 -0800 Subject: [PATCH 3/4] [Haml] Don't print errors for #escape_once under 1.9. --- doc-src/HAML_CHANGELOG.md | 5 +++++ lib/haml/helpers.rb | 4 +++- lib/haml/util.rb | 11 +++++++++++ test/haml/engine_test.rb | 5 +++++ test/haml/util_test.rb | 10 ++++++++++ test/test_helper.rb | 7 ++----- 6 files changed, 36 insertions(+), 6 deletions(-) diff --git a/doc-src/HAML_CHANGELOG.md b/doc-src/HAML_CHANGELOG.md index 214e3484..6bc4d4d9 100644 --- a/doc-src/HAML_CHANGELOG.md +++ b/doc-src/HAML_CHANGELOG.md @@ -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"`} diff --git a/lib/haml/helpers.rb b/lib/haml/helpers.rb index 3bb5f775..6a5172fd 100644 --- a/lib/haml/helpers.rb +++ b/lib/haml/helpers.rb @@ -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. diff --git a/lib/haml/util.rb b/lib/haml/util.rb index 7c6c863c..aa8c6998 100644 --- a/lib/haml/util.rb +++ b/lib/haml/util.rb @@ -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, diff --git a/test/haml/engine_test.rb b/test/haml/engine_test.rb index 6cbfed89..5e62fda1 100644 --- a/test/haml/engine_test.rb +++ b/test/haml/engine_test.rb @@ -1033,6 +1033,11 @@ END assert_equal("\n", render('%a{:b => "a #{1 + 1} b", :c => "d"}', :suppress_eval => true)) end + def test_utf8_attrs + assert_equal("\n", render("%a{:href => 'héllo'}")) + assert_equal("\n", render("%a(href='héllo')")) + end + # HTML 4.0 def test_html_has_no_self_closing_tags diff --git a/test/haml/util_test.rb b/test/haml/util_test.rb index a2b09c9d..560c2343 100644 --- a/test/haml/util_test.rb +++ b/test/haml/util_test.rb @@ -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)) diff --git a/test/test_helper.rb b/test/test_helper.rb index d5da2379..a31a675e 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -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 From dcad1e06df472685cb5c37465ced1a552cdd90d0 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Wed, 11 Nov 2009 14:46:38 -0800 Subject: [PATCH 4/4] [Haml] [html2haml] Don't die on XHTML Strict doctypes. Closes gh-57 --- doc-src/HAML_CHANGELOG.md | 2 ++ lib/haml/html.rb | 5 +---- test/haml/html2haml_test.rb | 9 +++++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/doc-src/HAML_CHANGELOG.md b/doc-src/HAML_CHANGELOG.md index 6bc4d4d9..8ef420e5 100644 --- a/doc-src/HAML_CHANGELOG.md +++ b/doc-src/HAML_CHANGELOG.md @@ -8,6 +8,8 @@ * 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"`} diff --git a/lib/haml/html.rb b/lib/haml/html.rb index 81334aeb..36acac60 100644 --- a/lib/haml/html.rb +++ b/lib/haml/html.rb @@ -152,10 +152,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 diff --git a/test/haml/html2haml_test.rb b/test/haml/html2haml_test.rb index 187e1779..5c2b545a 100644 --- a/test/haml/html2haml_test.rb +++ b/test/haml/html2haml_test.rb @@ -112,6 +112,15 @@ HTML render_rhtml('

">

')) end + # Regression Tests + + def test_xhtml_strict_doctype + assert_equal('!!! Strict', render(< +HTML + end + protected def render(text, options = {})