From f1a6cc9eec087e939122263e146f04a259278b05 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sun, 27 Sep 2009 17:37:22 -0700 Subject: [PATCH 1/6] [Haml] Raise an error when commas are omitted in static attributes. --- doc-src/HAML_CHANGELOG.md | 3 +++ lib/haml/precompiler.rb | 2 +- test/haml/engine_test.rb | 8 +++++++- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/doc-src/HAML_CHANGELOG.md b/doc-src/HAML_CHANGELOG.md index 4d8cc2bb..34d3a98e 100644 --- a/doc-src/HAML_CHANGELOG.md +++ b/doc-src/HAML_CHANGELOG.md @@ -11,6 +11,9 @@ * Don't crash when the `__FILE__` constant of a Ruby file is a relative path, as apparently happens sometimes in TextMate (thanks to [Karl Varga](http://github.com/kjvarga). + +* Raise an exception when commas are omitted in static attributes + (e.g. `%p{:foo => "bar" :baz => "bang"}`). ## [2.2.5](http://github.com/nex3/haml/commit/2.2.5) diff --git a/lib/haml/precompiler.rb b/lib/haml/precompiler.rb index 4ce32bce..e3df4eef 100644 --- a/lib/haml/precompiler.rb +++ b/lib/haml/precompiler.rb @@ -465,8 +465,8 @@ END return unless key = scanner.scan(LITERAL_VALUE_REGEX) return unless scanner.scan(/\s*=>\s*/) return unless value = scanner.scan(LITERAL_VALUE_REGEX) + return unless scanner.scan(/\s*(?:,|$)\s*/) attributes[eval(key).to_s] = eval(value).to_s - scanner.scan(/[,\s]*/) end text.count("\n").times { newline } attributes diff --git a/test/haml/engine_test.rb b/test/haml/engine_test.rb index 5c5b9ecf..7607fbdf 100644 --- a/test/haml/engine_test.rb +++ b/test/haml/engine_test.rb @@ -54,6 +54,7 @@ class EngineTest < Test::Unit::TestCase "%p(foo 'bar')" => "Invalid attribute list: \"(foo 'bar')\".", "%p(foo 'bar'\nbaz='bang')" => ["Invalid attribute list: \"(foo 'bar'\".", 1], "%p(foo='bar'\nbaz 'bang'\nbip='bop')" => ["Invalid attribute list: \"(foo='bar' baz 'bang'\".", 2], + "%p{:foo => 'bar' :bar => 'baz'}" => :compile, # Regression tests "- raise 'foo'\n\n\n\nbar" => ["foo", 1], @@ -737,7 +738,12 @@ HAML line_no ||= key.split("\n").length line_reported = err.backtrace[0].gsub(/\(.+\):/, '').to_i - assert_equal(expected_message, err.message, "Line: #{key}") + if expected_message == :compile + assert_match(/^compile error\n/, err.message, "Line: #{key}") + else + assert_equal(expected_message, err.message, "Line: #{key}") + end + assert_equal(line_no, line_reported, "Line: #{key}") else assert(false, "Exception not raised for\n#{key}") From e1a9fd62afd89844bbca6bc6580b5c60f4973e1f Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sun, 27 Sep 2009 17:38:15 -0700 Subject: [PATCH 2/6] [Haml] Add some more tests for compile errors. --- test/haml/engine_test.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/haml/engine_test.rb b/test/haml/engine_test.rb index 7607fbdf..6a43e5fc 100644 --- a/test/haml/engine_test.rb +++ b/test/haml/engine_test.rb @@ -55,6 +55,11 @@ class EngineTest < Test::Unit::TestCase "%p(foo 'bar'\nbaz='bang')" => ["Invalid attribute list: \"(foo 'bar'\".", 1], "%p(foo='bar'\nbaz 'bang'\nbip='bop')" => ["Invalid attribute list: \"(foo='bar' baz 'bang'\".", 2], "%p{:foo => 'bar' :bar => 'baz'}" => :compile, + "%p{:foo => }" => :compile, + "%p{=> 'bar'}" => :compile, + "%p{:foo => 'bar}" => :compile, + "%p{'foo => 'bar'}" => :compile, + "%p{:foo => 'bar\"}" => :compile, # Regression tests "- raise 'foo'\n\n\n\nbar" => ["foo", 1], From 2f9baa6a3101edff5b5b51c119068ed19ad0f55e Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sun, 20 Sep 2009 11:49:15 -0700 Subject: [PATCH 3/6] [Haml] Don't run tests in the haml-spec package. --- Rakefile | 1 + 1 file changed, 1 insertion(+) diff --git a/Rakefile b/Rakefile index 4951c241..3e7092ae 100644 --- a/Rakefile +++ b/Rakefile @@ -25,6 +25,7 @@ Rake::TestTask.new do |t| t.libs << 'lib' test_files = FileList['test/**/*_test.rb'] test_files.exclude('test/rails/*') + test_files.exclude('test/haml/spec/*') t.test_files = test_files t.verbose = true end From eca9a4059b2657816c39c7504c4bbf957dd32bc8 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sun, 27 Sep 2009 18:20:50 -0700 Subject: [PATCH 4/6] [Haml] Expand the exception test into multiple tests. --- test/haml/engine_test.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/haml/engine_test.rb b/test/haml/engine_test.rb index 6a43e5fc..d61eb430 100644 --- a/test/haml/engine_test.rb +++ b/test/haml/engine_test.rb @@ -733,15 +733,14 @@ HAML assert_equal("\nc\n", render("%a{'b' => 1 + 1}/\n= 'c'\n")) end - def test_exceptions - EXCEPTION_MAP.each do |key, value| + EXCEPTION_MAP.each do |key, value| + define_method("test_exception (#{key.inspect})") do begin - render(key, :filename => "(exception test for #{key.inspect})") + render(key, :filename => __FILE__) rescue Exception => err value = [value] unless value.is_a?(Array) expected_message, line_no = value line_no ||= key.split("\n").length - line_reported = err.backtrace[0].gsub(/\(.+\):/, '').to_i if expected_message == :compile assert_match(/^compile error\n/, err.message, "Line: #{key}") @@ -749,7 +748,7 @@ HAML assert_equal(expected_message, err.message, "Line: #{key}") end - assert_equal(line_no, line_reported, "Line: #{key}") + assert_match(/^#{Regexp.escape(__FILE__)}:#{line_no}/, err.backtrace[0], "Line: #{key}") else assert(false, "Exception not raised for\n#{key}") end From f858cce34f65f67b12ce8d2f34e576087cbbaf3e Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sun, 27 Sep 2009 22:55:36 -0700 Subject: [PATCH 5/6] Fix the ELPA-release code in the Rakefile. --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index 3e7092ae..3683725c 100644 --- a/Rakefile +++ b/Rakefile @@ -158,7 +158,7 @@ def mode_unchanged?(mode, version) mode_version = File.read("extra/#{mode}-mode.el").scan(/^;; Version: (.*)$/).first.first return false if mode_version == version return true unless changed_since?(mode_version, "extra/#{mode}-mode.el") - raise "#{mode}-mode.el version is #{haml_mode_version.inspect}, but it has changed as of #{version.inspect}" + raise "#{mode}-mode.el version is #{version.inspect}, but it has changed as of #{version.inspect}" return false end From 855de4ac88320c9632ea8239c8d7688ab3d01377 Mon Sep 17 00:00:00 2001 From: Nathan Weizenbaum Date: Sun, 27 Sep 2009 22:53:15 -0700 Subject: [PATCH 6/6] Bump version to 2.2.6. --- VERSION | 2 +- doc-src/HAML_CHANGELOG.md | 2 +- doc-src/SASS_CHANGELOG.md | 2 +- extra/haml-mode.el | 2 +- extra/sass-mode.el | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/VERSION b/VERSION index 21bb5e15..bda8fbec 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.2.5 +2.2.6 diff --git a/doc-src/HAML_CHANGELOG.md b/doc-src/HAML_CHANGELOG.md index 8c7a51c3..93ec5a3b 100644 --- a/doc-src/HAML_CHANGELOG.md +++ b/doc-src/HAML_CHANGELOG.md @@ -3,7 +3,7 @@ * Table of contents {:toc} -## 2.2.6 (Unreleased) +## [2.2.6](http://github.com/nex3/haml/commit/2.2.6) * Made the error message when unable to load a dependency for html2haml respect the `--trace` option. diff --git a/doc-src/SASS_CHANGELOG.md b/doc-src/SASS_CHANGELOG.md index ffcaaf8a..7f11f84d 100644 --- a/doc-src/SASS_CHANGELOG.md +++ b/doc-src/SASS_CHANGELOG.md @@ -3,7 +3,7 @@ * Table of contents {:toc} -## 2.2.6 (Unreleased) +## [2.2.6](http://github.com/nex3/haml/commit/2.2.6) * Don't crash when the `__FILE__` constant of a Ruby file is a relative path, as apparently happens sometimes in TextMate diff --git a/extra/haml-mode.el b/extra/haml-mode.el index d6bbaa30..d759d0ff 100644 --- a/extra/haml-mode.el +++ b/extra/haml-mode.el @@ -4,7 +4,7 @@ ;; Author: Nathan Weizenbaum ;; URL: http://github.com/nex3/haml/tree/master -;; Version: 2.2.5 +;; Version: 2.2.6 ;; Created: 2007-03-08 ;; By: Nathan Weizenbaum ;; Keywords: markup, language, html diff --git a/extra/sass-mode.el b/extra/sass-mode.el index 033fe9dd..bcad284d 100644 --- a/extra/sass-mode.el +++ b/extra/sass-mode.el @@ -4,7 +4,7 @@ ;; Author: Nathan Weizenbaum ;; URL: http://github.com/nex3/haml/tree/master -;; Version: 2.2.5 +;; Version: 2.2.6 ;; Created: 2007-03-15 ;; By: Nathan Weizenbaum ;; Keywords: markup, language, css