diff --git a/lib/css_parser/rule_set.rb b/lib/css_parser/rule_set.rb index 793e80f..196b400 100644 --- a/lib/css_parser/rule_set.rb +++ b/lib/css_parser/rule_set.rb @@ -512,6 +512,11 @@ def create_background_shorthand! # :nodoc: def create_border_shorthand! # :nodoc: values = [] + # can't merge if not shortened + declarations.each do |name, _value| + return nil if %w[border-top border-right border-bottom border-left].any? { |e| name.include?(e) } + end + BORDER_STYLE_PROPERTIES.each do |property| next unless (declaration = declarations[property]) next if declaration.important diff --git a/test/test_rule_set_creating_shorthand.rb b/test/test_rule_set_creating_shorthand.rb index e388546..ad3e9e6 100644 --- a/test/test_rule_set_creating_shorthand.rb +++ b/test/test_rule_set_creating_shorthand.rb @@ -50,6 +50,16 @@ def test_combining_borders_into_shorthand } combined = create_shorthand(properties) assert_equal '#bada55 #000000 #ffffff #ff0000;', combined['border-color'] + + # should not combine if individual side property is set + properties = { + 'border-top-style' => 'none', + 'border-width' => '1px', + 'border-style' => 'solid', + 'border-color' => 'black' + } + combined = create_shorthand(properties) + assert_equal '', combined['border'] end # Dimensions shorthand