FIX: correct race condition loading library

FIX: correct race condition loading library

In some very rare cases CssParser could be loaded but CssParser::Parser not this ensures we check for the actual constant we plan to call for concurrent digest generations

diff --git a/lib/email/styles.rb b/lib/email/styles.rb
index a3ccd7c..90ec15d 100644
--- a/lib/email/styles.rb
+++ b/lib/email/styles.rb
@@ -40,9 +40,11 @@ module Email
       @custom_styles = {}
 
       if !css.blank?
-        require 'css_parser' unless defined?(CssParser)
+        # there is a minor race condition here, CssParser could be
+        # loaded by ::CssParser::Parser not loaded
+        require 'css_parser' unless defined?(::CssParser::Parser)
 
-        parser = CssParser::Parser.new(import: false)
+        parser = ::CssParser::Parser.new(import: false)
         parser.load_string!(css)
         parser.each_selector do |selector, value|
           @custom_styles[selector] ||= +''

GitHub sha: d05b724c

1 Like