File tree Expand file tree Collapse file tree
lib/fastimage/fastimage_parsing Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -57,7 +57,12 @@ def type
5757 # unknown. We assume the <svg tag cannot be within 10 chars of the end of
5858 # the file, and is within the first 1000 chars.
5959 begin
60- :svg if ( 1 ..100 ) . detect { |n | @stream . peek ( 10 * n ) . include? ( "<svg" ) }
60+ :svg if ( 1 ..100 ) . any? { |n |
61+ peeked = @stream . peek ( 10 * n )
62+ svg_index = peeked . index ( "<svg" )
63+ html_index = peeked . index ( /<html/i )
64+ svg_index && ( !html_index || svg_index < html_index )
65+ }
6166 rescue FiberError , FastImage ::CannotParseImage
6267 nil
6368 end
Original file line number Diff line number Diff line change 1+ <!DOCTYPE html>
2+ < html lang ="en ">
3+ < head > < title > Test</ title > </ head >
4+ < body >
5+ < svg viewBox ="0 0 100 100 "> < rect width ="50 " height ="50 "/> </ svg >
6+ </ body >
7+ </ html >
Original file line number Diff line number Diff line change @@ -189,6 +189,12 @@ def test_should_raise_image_fetch_failure_error_if_net_unreach_exception_happens
189189 end
190190 end
191191
192+ def test_should_raise_unknown_image_type_when_file_is_html_with_inline_svg
193+ assert_raises ( FastImage ::UnknownImageType ) do
194+ FastImage . size ( File . join ( FixturePath , "test8.html" ) , :raise_on_failure => true )
195+ end
196+ end
197+
192198 def test_should_raise_unknown_image_type_when_file_is_non_svg_xml
193199 [ "test.xml" , "test2.xml" ] . each do |fn |
194200 assert_raises ( FastImage ::UnknownImageType ) do
You can’t perform that action at this time.
0 commit comments