Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/css_parser/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ def to_s(which_media = :all)
each_selector(which_media) do |selectors, declarations, specificity, media_types|
media_types.each do |media_type|
styles_by_media_types[media_type] ||= []
next if styles_by_media_types[media_type].include?([selectors, declarations])
styles_by_media_types[media_type] << [selectors, declarations]
end
end
Expand Down
19 changes: 19 additions & 0 deletions test/test_css_parser_media_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,25 @@ def setup
@cp = Parser.new
end

def test_that_duplicate_media_queries_do_not_duplicate_rules
query_to_duplicate = ["only screen and (max-width: 480px)"]*100
@cp.add_block!(<<-CSS)
@media only screen and (max-width: 480px), #{query_to_duplicate.join(', ')} {
body { color: red; }
}
CSS

expected = <<-CSS
@media only screen and (max-width: 480px) {
body {
color: red;
}
}
CSS

assert_equal expected, @cp.to_s
end

def test_that_media_types_dont_include_all
@cp.add_block!(<<-CSS)
@media handheld {
Expand Down