Skip to content

Commit

Permalink
Fixed exception on parsing pseudo-classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
ihoka committed Apr 15, 2010
1 parent 832eb79 commit 7bce179
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/mail_style/inline_styles.rb
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
9 changes: 8 additions & 1 deletion spec/inline_styles_spec.rb
Expand Up @@ -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 => '<p class="text">Hello World</p>'
part :content_type => 'text/html', :body => '<p class="text">Hello <a href="htt://example.com/">World</a></p>'
part :content_type => 'text/plain', :body => 'Hello World'
end

Expand Down Expand Up @@ -98,6 +98,13 @@ def setup_email(css_file = nil)
it "should add both styles to paragraph" do
should match(/<p class="text" style="color: #0f0;font-size: 14px;line-height: 1.5">/)
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
Expand Down

0 comments on commit 7bce179

Please sign in to comment.