Skip to content

Commit

Permalink
Make sure images are base64-encoded PNGs (#178)
Browse files Browse the repository at this point in the history
  • Loading branch information
maximevaillancourt authored and NathanPJF committed Mar 29, 2019
1 parent 1ae4cea commit 82c9b76
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ All icon contributions must follow the guidelines below. The **markup** guidelin
- `id` attribute with the value `pi-` + the name of your icon, (same as the `aria-labelledby`)
- Inner text containing the label of your icon
- The `<svg>` must use vector graphics, i.e. `path`, `rect`, etc.
- Nested `<image>` or `<img>` elements will not be accepted.
- Nested `<image>` or `<img>` elements will only be accepted if they contain base64-encoded PNG image data. Paths to image files will not be accepted.
- Embedded fonts or bitmaps will not be accepted.
- All `id` attributes start with `pi-`.
Expand Down
17 changes: 17 additions & 0 deletions test/unit/payment_icon_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,21 @@ class PaymentIconTest < ActiveSupport::TestCase
message: "The '#{payment_type}' SVG file should have a aria-labelledby='#{ICON_ID_PREFIX}#{payment_type}' attribute on the root <svg> node"
end
end

test 'Payment icon SVGs with <img> or <image> tags base64-encode PNG image data' do
SVG_PAYMENT_TYPES.each do |payment_type, svg|
document = Nokogiri::XML.parse(svg)

image_nodes = []
image_nodes << document.search("img")
image_nodes << document.search("image")
image_nodes.flatten!.uniq!

image_nodes.each do |image_node|
xlink_href_content = image_node['xlink:href']
error_message = "Expected image tag to contain base64 encoded PNG, found '#{xlink_href_content.truncate(50)}' instead"
assert xlink_href_content.start_with?('data:image/png;base64'), error_message
end
end
end
end

0 comments on commit 82c9b76

Please sign in to comment.