From 69ee94b526ad6c34cb7721e1192794ada4a454dd Mon Sep 17 00:00:00 2001 From: Gerhard Schlager Date: Tue, 26 May 2020 17:07:16 +0200 Subject: [PATCH] FIX: XML files could be detected as SVG files --- lib/freedom_patches/fast_image.rb | 21 ++++++++++ .../freedom_patches/fast_image_spec.rb | 40 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 lib/freedom_patches/fast_image.rb create mode 100644 spec/components/freedom_patches/fast_image_spec.rb diff --git a/lib/freedom_patches/fast_image.rb b/lib/freedom_patches/fast_image.rb new file mode 100644 index 00000000000..836791b977e --- /dev/null +++ b/lib/freedom_patches/fast_image.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +# Remove when https://github.com/sdsykes/fastimage/pull/115 +# has been merged. Please remove the specs as well. +class FastImage + attr_reader :original_type + + private + + old_parse_type = instance_method(:parse_type) + + define_method(:parse_type) do + @original_type = old_parse_type.bind(self).() + + if @original_type == :svg && @stream.peek(2) == " + + + SVG + end + + let(:xml_file) do + StringIO.new(<<~XML) + + + + + + XML + end + + it "correctly detects SVG" do + expect(FastImage.new(svg_file).type).to eq(:svg) + end + + it "doesn't detect XML starting with