css_parser 3.1.0 → 3.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c675c0d95c9efce004a49e17cf09c880c44c4c11375f754c50586052c03202d
4
- data.tar.gz: 2d729de7e39e045d1e2594e4c847c495ef7765d34c37b76f53ef9348de0e1f96
3
+ metadata.gz: ed961d9c30e5f86976f527c41b777f29bdd558b5e149985e536ba74876fbb6c8
4
+ data.tar.gz: d12338993a30625469c3cd7ff81932744c877f945a4b361a524744593589a820
5
5
  SHA512:
6
- metadata.gz: ab3178e90c357ad4ede9c90ac70526bbe4b90a475690afa60551d4acfc2bb41a70db125bdda040a1bbcfa8f4e3dfa454401116aec745e639af9244c71c3f7c6a
7
- data.tar.gz: 15838f208ef82d6a2d5adbddcb5486ad5b13b0d88f32e3923b6f7bd064fbbe08dc4f6dc4af0a299a517ff7c4faec3010a044b59209b809248e58622b08a29c4a
6
+ metadata.gz: c1c189987171a935f347f7fe7f1f528ae2b2ce2d6880eaf6f124ea05c45b4af02685bf765b128188fdc33add0bde3b76b401a99d8268f1534feba6e962a35632
7
+ data.tar.gz: 5cc19fa3c0047c20331240acd7c3064afdae0d43227de44a7a347eb7239119b09b287225cfaf8840535aa59ce9511f7b467c059b18298424c55231276cb2db3f
@@ -61,20 +61,27 @@ module CssParser
61
61
  RE_BORDER_UNITS = Regexp.union(BOX_MODEL_UNITS_RX, /(thin|medium|thick)/i)
62
62
 
63
63
  # Functions like calc, var, clamp, etc.
64
- RE_FUNCTIONS = /
65
- (
66
- [a-z0-9-]+ # function name
67
- )
68
- (?>
69
- \( # opening parenthesis
70
- (?:
71
- ([^()]+)
72
- | # recursion via subexpression
73
- \g<0>
74
- )*
75
- \) # closing parenthesis
76
- )
77
- /imx.freeze
64
+ # Possessive quantifiers + recursion-first alternation avoid exponential
65
+ # backtracking on unclosed functions, the timeout is a backstop.
66
+ RE_FUNCTIONS = Regexp.new(
67
+ /
68
+ (
69
+ [a-z0-9-]+ # function name
70
+ )
71
+ (?>
72
+ \( # opening parenthesis
73
+ (?:
74
+ \g<0> # nested function
75
+ |
76
+ [^()a-z0-9]++
77
+ |
78
+ [a-z0-9-]++ (?!\()
79
+ )*
80
+ \) # closing parenthesis
81
+ )
82
+ /imx,
83
+ timeout: 0.01
84
+ ).freeze
78
85
 
79
86
  # Patterns for specificity calculations
80
87
  NON_ID_ATTRIBUTES_AND_PSEUDO_CLASSES_RX_NC = /
@@ -696,10 +696,16 @@ module CssParser
696
696
  end
697
697
 
698
698
  def split_value_preserving_function_whitespace(value)
699
- split_value = value.gsub(RE_FUNCTIONS) do |c|
700
- c.gsub!(/\s+/, WHITESPACE_REPLACEMENT)
701
- c
702
- end
699
+ # hostile values can still hit the regexp timeout, then split without protecting functions
700
+ split_value =
701
+ begin
702
+ value.gsub(RE_FUNCTIONS) do |c|
703
+ c.gsub!(/\s+/, WHITESPACE_REPLACEMENT)
704
+ c
705
+ end
706
+ rescue Regexp::TimeoutError
707
+ value
708
+ end
703
709
 
704
710
  matches = split_value.strip.split(/\s+/)
705
711
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CssParser
4
- VERSION = '3.1.0'.freeze
4
+ VERSION = '3.2.0'.freeze
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: css_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Dunae