From a76b25d1a5a47184836cf0c37c2b8c608b60f389 Mon Sep 17 00:00:00 2001 From: nex3 Date: Thu, 10 Jan 2008 08:40:00 +0000 Subject: [PATCH] Fixing a bug where the #.-syntax class or id of a Haml tag would be overwritten by setting the value in the attrs hash to nil. Thanks to Aman Gupta for pointing this out. git-svn-id: svn://hamptoncatlin.com/haml/trunk@726 7063305b-7217-0410-af8c-cdc13e5119b9 --- lib/haml/buffer.rb | 4 ++++ test/haml/engine_test.rb | 13 +++++++++++++ 2 files changed, 17 insertions(+) diff --git a/lib/haml/buffer.rb b/lib/haml/buffer.rb index 8f066601..3906296c 100644 --- a/lib/haml/buffer.rb +++ b/lib/haml/buffer.rb @@ -123,11 +123,15 @@ module Haml def self.merge_attrs(to, from) if to['id'] && from['id'] to['id'] << '_' << from.delete('id') + elsif to['id'] || from['id'] + from['id'] ||= to['id'] end if to['class'] && from['class'] # Make sure we don't duplicate class names from['class'] = (from['class'].split(' ') | to['class'].split(' ')).join(' ') + elsif to['class'] || from['class'] + from['class'] ||= to['class'] end to.merge!(from) diff --git a/test/haml/engine_test.rb b/test/haml/engine_test.rb index de99fb8d..b1850017 100644 --- a/test/haml/engine_test.rb +++ b/test/haml/engine_test.rb @@ -139,6 +139,19 @@ class EngineTest < Test::Unit::TestCase assert_equal("

nil

\n", render("%p{ :attr => x } nil", :locals => {:x => nil})) end + def test_nil_id_with_syntactic_id + assert_equal("

nil

\n", render("%p#foo{:id => nil} nil")) + assert_equal("

nil

\n", render("%p#foo{{:id => 'bar'}, :id => nil} nil")) + assert_equal("

nil

\n", render("%p#foo{{:id => nil}, :id => 'bar'} nil")) + end + + def test_nil_class_with_syntactic_class + assert_equal("

nil

\n", render("%p.foo{:class => nil} nil")) + assert_equal("

nil

\n", render("%p.bar.foo{:class => nil} nil")) + assert_equal("

nil

\n", render("%p.foo{{:class => 'bar'}, :class => nil} nil")) + assert_equal("

nil

\n", render("%p.foo{{:class => nil}, :class => 'bar'} nil")) + end + def test_locals assert_equal("

Paragraph!

\n", render("%p= text", :locals => { :text => "Paragraph!" })) end