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
This commit is contained in:
Sam Saffron 2019-08-15 17:16:41 +10:00
parent f7c648e3af
commit d05b724c4e
1 changed files with 4 additions and 2 deletions

View File

@ -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] ||= +''