From c7f3aec09293a70749f27c416176c8da3c7ab8c1 Mon Sep 17 00:00:00 2001 From: Cyril Le Roy Date: Tue, 9 Feb 2021 14:25:40 +0100 Subject: [PATCH 1/3] Prevent border shorthand when individual property isnt shortened --- lib/css_parser/rule_set.rb | 5 +++++ test/test_rule_set_creating_shorthand.rb | 10 ++++++++++ 2 files changed, 15 insertions(+) diff --git a/lib/css_parser/rule_set.rb b/lib/css_parser/rule_set.rb index 793e80f..8f0af24 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 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..08802cc 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 From 2a34af5d01afd7447aca6db91bb7761cd63ad435 Mon Sep 17 00:00:00 2001 From: Cyril Le Roy Date: Tue, 9 Feb 2021 16:07:09 +0100 Subject: [PATCH 2/3] rubocop --- test/test_rule_set_creating_shorthand.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/test_rule_set_creating_shorthand.rb b/test/test_rule_set_creating_shorthand.rb index 08802cc..ad3e9e6 100644 --- a/test/test_rule_set_creating_shorthand.rb +++ b/test/test_rule_set_creating_shorthand.rb @@ -56,7 +56,7 @@ def test_combining_borders_into_shorthand 'border-top-style' => 'none', 'border-width' => '1px', 'border-style' => 'solid', - 'border-color' => 'black', + 'border-color' => 'black' } combined = create_shorthand(properties) assert_equal '', combined['border'] From ce253ea714f71b1dd72ac8c4b209a91eb00e03ba Mon Sep 17 00:00:00 2001 From: Cyril Le Roy Date: Tue, 9 Feb 2021 16:08:45 +0100 Subject: [PATCH 3/3] rubocop2 --- lib/css_parser/rule_set.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/css_parser/rule_set.rb b/lib/css_parser/rule_set.rb index 8f0af24..196b400 100644 --- a/lib/css_parser/rule_set.rb +++ b/lib/css_parser/rule_set.rb @@ -513,8 +513,8 @@ def create_border_shorthand! # :nodoc: values = [] # can't merge if not shortened - declarations.each do |name, value| - return if %w(border-top border-right border-bottom border-left).any? { |e| name.include?(e) } + 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|