From 7fe280fdae85bb64856669bf2aad5c9ec916d56c Mon Sep 17 00:00:00 2001 From: J Smith Date: Mon, 26 Jul 2021 12:18:41 -0300 Subject: [PATCH] Move whitespace preserving split to `RuleSet#split_value_preserving_whitespace` --- lib/css_parser/rule_set.rb | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/lib/css_parser/rule_set.rb b/lib/css_parser/rule_set.rb index 82cbc87..99ae5bb 100644 --- a/lib/css_parser/rule_set.rb +++ b/lib/css_parser/rule_set.rb @@ -359,9 +359,8 @@ def expand_dimensions_shorthand! # :nodoc: # # TODO: rgba, hsl, hsla value.gsub!(RE_COLOUR) { |c| c.gsub(/(\s*,\s*)/, ',') } - value.gsub!(RE_FUNCTIONS) { |c| c.gsub(/\s+/, WHITESPACE_REPLACEMENT) } - matches = value.strip.split(/\s+/) + matches = split_value_preserving_whitespace(value) case matches.length when 1 @@ -640,6 +639,21 @@ def parse_selectors!(selectors) # :nodoc: s end end + + def split_value_preserving_whitespace(value) + split_value = value.gsub(RE_FUNCTIONS) do |c| + c.gsub!(/\s+/, WHITESPACE_REPLACEMENT) + c + end + + matches = split_value.strip.split(/\s+/) + + matches.each do |c| + c.gsub!(WHITESPACE_REPLACEMENT, ' ') + end + + matches + end end class OffsetAwareRuleSet < RuleSet