mirror of
https://github.com/sdsykes/fastimage.git
synced 2025-12-30 00:05:02 -05:00
Fix parsing for svg with longer preamble
This commit is contained in:
parent
ab07d1fe21
commit
bd150b54af
@ -60,6 +60,7 @@ require 'pathname'
|
||||
require 'zlib'
|
||||
require 'base64'
|
||||
require 'uri'
|
||||
require 'fiber'
|
||||
|
||||
# see http://stackoverflow.com/questions/5208851/i/41048816#41048816
|
||||
if RUBY_VERSION < "2.2"
|
||||
@ -417,6 +418,7 @@ class FastImage
|
||||
@str = ''
|
||||
end
|
||||
|
||||
# Peeking beyond the end of the input will raise
|
||||
def peek(n)
|
||||
while @strpos + n - 1 >= @str.size
|
||||
unused_str = @str[@strpos..-1]
|
||||
@ -488,7 +490,14 @@ class FastImage
|
||||
when "<s"
|
||||
:svg
|
||||
when "<?"
|
||||
:svg if @stream.peek(100).include?("<svg")
|
||||
# Peek 10 more chars each time, and if end of file is reached just raise
|
||||
# unknown. We assume the <svg tag cannot be within 10 chars of the end of
|
||||
# the file, and is within the first 250 chars.
|
||||
begin
|
||||
:svg if (1..25).detect {|n| @stream.peek(10 * n).include?("<svg")}
|
||||
rescue FiberError
|
||||
nil
|
||||
end
|
||||
end
|
||||
|
||||
parsed_type or raise UnknownImageType
|
||||
@ -724,10 +733,12 @@ class FastImage
|
||||
end
|
||||
when /\w/
|
||||
attr_name << char
|
||||
when "<"
|
||||
attr_name = [char]
|
||||
when ">"
|
||||
state = :stop if state == :started
|
||||
else
|
||||
state = :started if attr_name.join == "svg"
|
||||
state = :started if attr_name.join == "<svg"
|
||||
attr_name.clear
|
||||
end
|
||||
end
|
||||
|
||||
1
test/fixtures/test2.svg
vendored
Normal file
1
test/fixtures/test2.svg
vendored
Normal file
@ -0,0 +1 @@
|
||||
<?xml version="1.0" standalone="no"?><!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"><svg version="1.1" width="366" height="271" xmlns="http://www.w3.org/2000/svg"><path stroke="#000000" stroke-width="2" fill="none" d="M87 103 L91 109 M91 109 L108 119 M108 119 L133 126 M133 126 L166 133 M166 133 L199 142 M199 142 L227 150 M227 150 L243 154 M243 154 L251 152 M251 152 L253 149 M253 149 L246 141 M246 141 L221 125 M221 125 L187 112 M187 112 L149 97 M149 97 L90 82 M90 82 L72 82 M72 82 L60 83 M60 83 L53 85 M53 85 L51 86 M51 86 L64 101 M64 101 L85 116 M85 116 L113 132 M113 132 L142 146 M142 146 L185 163 M185 163 L201 169 M201 169 L212 172 M212 172 L222 175 M222 175 L230 177 M230 177 L242 179 M242 179 L245 179 M245 179 L245 179 " /></svg>
|
||||
|
After Width: | Height: | Size: 791 B |
@ -33,7 +33,8 @@ GoodFixtures = {
|
||||
"webp_vp8l.webp" => [:webp, [386, 395]],
|
||||
"webp_vp8.webp" => [:webp, [550, 368]],
|
||||
"test.svg" => [:svg, [200, 300]],
|
||||
"test_partial_viewport.svg" => [:svg, [860, 400]]
|
||||
"test_partial_viewport.svg" => [:svg, [860, 400]],
|
||||
"test2.svg" => [:svg, [366, 271]]
|
||||
}
|
||||
|
||||
BadFixtures = [
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user