From 7bce179ea95ccfcce75a3f70de85e6fe6be9b79c Mon Sep 17 00:00:00 2001 From: Istvan Hoka Date: Thu, 15 Apr 2010 18:54:09 +0300 Subject: [PATCH] Fixed exception on parsing pseudo-classes. --- lib/mail_style/inline_styles.rb | 2 ++ spec/inline_styles_spec.rb | 9 ++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/lib/mail_style/inline_styles.rb b/lib/mail_style/inline_styles.rb index bb9d2a8..1deb4d9 100644 --- a/lib/mail_style/inline_styles.rb +++ b/lib/mail_style/inline_styles.rb @@ -14,6 +14,7 @@ def create_mail_with_inline_styles protected + # Flatten nested parts def collect_parts(parts) nested = !parts.empty? ? parts.map { |p| collect_parts(p.parts) }.flatten : [] [parts, nested].flatten @@ -41,6 +42,7 @@ def parse_html(html) element_styles = {} css_parser.each_selector do |selector, declaration, specificity| + next if selector.include?(':') html_document.css(selector).each do |element| declaration.to_s.split(';').each do |style| # Split style in attribute and value diff --git a/spec/inline_styles_spec.rb b/spec/inline_styles_spec.rb index 90118ed..aec06f1 100644 --- a/spec/inline_styles_spec.rb +++ b/spec/inline_styles_spec.rb @@ -15,7 +15,7 @@ class TestMailer < ActionMailer::Base def test_multipart(css_file = nil) setup_email(css_file) content_type 'multipart/alternative' - part :content_type => 'text/html', :body => '

Hello World

' + part :content_type => 'text/html', :body => '

Hello World

' part :content_type => 'text/plain', :body => 'Hello World' end @@ -98,6 +98,13 @@ def setup_email(css_file = nil) it "should add both styles to paragraph" do should match(/

/) end + + it "should not crash on :pseudo-classes" do + css_rules("a:link { color: #f00 }") + expect do + subject + end.to_not raise_error(StandardError) + end end describe 'Inline styles' do