diff --git a/lib/zendesk_apps_support/package.rb b/lib/zendesk_apps_support/package.rb index 67971f89..998f77bf 100644 --- a/lib/zendesk_apps_support/package.rb +++ b/lib/zendesk_apps_support/package.rb @@ -44,8 +44,6 @@ def validate(marketplace: true, skip_marketplace_translations: false) end errors << Validations::Banner.call(self) if has_banner? - errors << Validations::Svg.call(self) if has_svgs? - errors.flatten.compact end @@ -55,6 +53,15 @@ def validate!(marketplace: true, skip_marketplace_translations: false) true end + def curl_zam_svg_validation_endpoint + begin + require 'net/http' + response = Net::HTTP.get_response(URI("https://appsubmission.zendesk.com/apps/zat_validation?params=#{self}")) + raise "There was an error in validation of svgs" if response.status != 200 + true + end + end + def assets @assets ||= Dir.chdir(root) do Dir['assets/**/*'].select { |f| File.file?(f) } @@ -92,10 +99,6 @@ def lib_files @lib_files ||= js_files.select { |f| f =~ %r{^lib/} } end - def svg_files - @svg_files ||= files.select { |f| f =~ %r{^assets/.*\.svg$} } - end - def template_files files.select { |f| f =~ %r{^templates/.*\.hdbs$} } end @@ -187,10 +190,6 @@ def has_file?(path) File.file?(path_to(path)) end - def has_svgs? - svg_files.any? - end - def has_requirements? has_file?(REQUIREMENTS_FILENAME) end diff --git a/lib/zendesk_apps_support/validations/svg.rb b/lib/zendesk_apps_support/validations/svg.rb deleted file mode 100644 index 57c3e794..00000000 --- a/lib/zendesk_apps_support/validations/svg.rb +++ /dev/null @@ -1,81 +0,0 @@ -# frozen_string_literal: true - -require 'loofah' - -module ZendeskAppsSupport - module Validations - module Svg - PLACEHOLDER_SVG_MARKUP = File.read(File.expand_path('../../assets/default_app_logo.svg', __FILE__)) - - # whitelist elements and attributes used in Zendesk Garden assets - Loofah::HTML5::WhiteList::ALLOWED_ELEMENTS_WITH_LIBXML2.add 'symbol' - Loofah::HTML5::WhiteList::ACCEPTABLE_CSS_PROPERTIES.add 'position' - - # CRUFT: ignore a (very specific) style attribute which Loofah would otherwise scrub. - # This attribute is deprecated (https://www.w3.org/TR/filter-effects/#AccessBackgroundImage) - # but is included in many of the test apps used in fixtures for tests in ZAM, ZAT etc. - Loofah::HTML5::WhiteList::ACCEPTABLE_CSS_PROPERTIES.add 'enable-background' - - @strip_declaration = Loofah::Scrubber.new do |node| - node.remove if node.name == 'xml' && node.children.empty? - end - - # Loofah's default scrubber strips spaces between CSS attributes. Passing the input markup through this scrubber - # first ensures that this stripped whitespace in the output doesn't register as a diff. - @strip_spaces_between_css_attrs = Loofah::Scrubber.new do |node| - match_pattern = Regexp.new(/\;\s+/) - if node.name == 'svg' && node['style'] - node['style'] = node['style'].gsub(match_pattern, ';') - end - end - - @empty_malformed_markup = Loofah::Scrubber.new do |node| - node.next.remove while node.name == 'svg' && node.next - end - - class << self - def contains_embedded_bitmap?(markup) - Nokogiri::XML(markup).css('//image').any? - end - - def rewrite_svg(svg, new_markup, package, errors) - warning_string = if contains_embedded_bitmap?(svg.read) - 'txt.apps.admin.warning.app_build.bitmap_in_svg' - else - 'txt.apps.admin.warning.app_build.sanitised_svg' - end - - package.warnings << I18n.t(warning_string, svg: svg.relative_path) - compressed_new_markup = new_markup.tr("\n", '').squeeze(' ').gsub(/\>\s+\<') - IO.write(svg.absolute_path, compressed_new_markup) - rescue - errors << ValidationError.new(:dirty_svg, svg: svg.relative_path) - end - - def call(package) - errors = [] - - package.svg_files.each do |svg| - if contains_embedded_bitmap?(svg.read) - rewrite_svg(svg, PLACEHOLDER_SVG_MARKUP, package, errors) - else - markup = Loofah.xml_fragment(svg.read) - .scrub!(@strip_declaration) - .scrub!(@strip_spaces_between_css_attrs) - .to_xml.strip - - clean_markup = Loofah.xml_fragment(markup) - .scrub!(:prune) - .scrub!(@empty_malformed_markup) - .to_xml - - next if clean_markup == markup - rewrite_svg(svg, clean_markup, package, errors) - end - end - errors - end - end - end - end -end diff --git a/zendesk_apps_support.gemspec b/zendesk_apps_support.gemspec index 685d6b81..8557b099 100644 --- a/zendesk_apps_support.gemspec +++ b/zendesk_apps_support.gemspec @@ -20,8 +20,6 @@ Gem::Specification.new do |s| s.add_runtime_dependency 'image_size' s.add_runtime_dependency 'erubis' s.add_runtime_dependency 'jshintrb', '~> 0.3.0' - s.add_runtime_dependency 'loofah', '~> 2.2.3' - s.add_runtime_dependency 'nokogiri', '~> 1.8.5' s.add_runtime_dependency 'rb-inotify', '0.9.10' s.add_development_dependency 'rspec', '~> 3.4.0'