prawn-svg 0.36.0 → 0.36.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/prawn/svg/document.rb +15 -12
- data/lib/prawn/svg/version.rb +1 -1
- data/spec/prawn/svg/document_spec.rb +18 -4
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 28ccc4cc947f9d497484516d673f66098fd4624e11aba0035afc4d4373ec27cc
|
4
|
+
data.tar.gz: 19344cb3568acff4b85de31d199024070dacaa10eeaf4305d9d35265a547dbda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 535e9463f1577596e42889fec04c0d0a41cfb30ee6cd0c293c4a028987bde0bf607c482767d1d916445ad7042d14c653a696e2da9c096ff8e40dc6ccc3a69ae6
|
7
|
+
data.tar.gz: 929c06b75e31fd7314b5ade1ad86f00a6b4d8b98fceff0f66672cf7f1a0b1b70cf75fc28461042c8f91915d43bc5778ea27e49d6aa00aa280037835f9683db8c
|
data/Gemfile.lock
CHANGED
data/lib/prawn/svg/document.rb
CHANGED
@@ -18,18 +18,9 @@ class Prawn::SVG::Document
|
|
18
18
|
|
19
19
|
def initialize(data, bounds, options, font_registry: nil, css_parser: CssParser::Parser.new, attribute_overrides: {})
|
20
20
|
begin
|
21
|
-
@root = REXML::Document.new(data).root
|
22
|
-
rescue REXML::ParseException
|
23
|
-
|
24
|
-
end
|
25
|
-
|
26
|
-
if @root.nil?
|
27
|
-
if data.respond_to?(:end_with?) && data.end_with?('.svg')
|
28
|
-
raise InvalidSVGData,
|
29
|
-
"The data supplied is not a valid SVG document. It looks like you've supplied a filename instead; use IO.read(filename) to get the data before you pass it to prawn-svg."
|
30
|
-
else
|
31
|
-
raise InvalidSVGData, 'The data supplied is not a valid SVG document.'
|
32
|
-
end
|
21
|
+
@root = REXML::Document.new(data).root or raise_parse_error(data)
|
22
|
+
rescue REXML::ParseException => e
|
23
|
+
raise_parse_error(data, e.message)
|
33
24
|
end
|
34
25
|
|
35
26
|
@warnings = []
|
@@ -73,4 +64,16 @@ class Prawn::SVG::Document
|
|
73
64
|
raise ArgumentError, ':color_mode must be set to :rgb (default) or :cmyk'
|
74
65
|
end
|
75
66
|
end
|
67
|
+
|
68
|
+
def raise_parse_error(data, exception_message = nil)
|
69
|
+
message = 'The data supplied is not a valid SVG document.'
|
70
|
+
|
71
|
+
if data.respond_to?(:end_with?) && data.end_with?('.svg')
|
72
|
+
message += " It looks like you've supplied a filename instead; use File.read(filename) to get the data from the file before you pass it to prawn-svg."
|
73
|
+
end
|
74
|
+
|
75
|
+
message += "\n#{exception_message}" if exception_message
|
76
|
+
|
77
|
+
raise InvalidSVGData, message
|
78
|
+
end
|
76
79
|
end
|
data/lib/prawn/svg/version.rb
CHANGED
@@ -25,10 +25,22 @@ describe Prawn::SVG::Document do
|
|
25
25
|
context 'when unparsable XML is provided' do
|
26
26
|
let(:svg) { "this isn't SVG data" }
|
27
27
|
|
28
|
-
it
|
28
|
+
it "raises an exception, passing on REXML's error message" do
|
29
29
|
expect do
|
30
30
|
Prawn::SVG::Document.new(svg, bounds, options)
|
31
|
-
end.to raise_error Prawn::SVG::Document::InvalidSVGData,
|
31
|
+
end.to raise_error Prawn::SVG::Document::InvalidSVGData,
|
32
|
+
/\AThe data supplied is not a valid SVG document.+Malformed.+#{Regexp.escape(svg)}/m
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'when broken XML is provided' do
|
37
|
+
let(:svg) { '<svg><g><rect></rect></svg>' }
|
38
|
+
|
39
|
+
it "raises an exception, passing on REXML's error message" do
|
40
|
+
expect do
|
41
|
+
Prawn::SVG::Document.new(svg, bounds, options)
|
42
|
+
end.to raise_error Prawn::SVG::Document::InvalidSVGData,
|
43
|
+
/\AThe data supplied is not a valid SVG document.+Missing end tag for 'g'/m
|
32
44
|
end
|
33
45
|
end
|
34
46
|
|
@@ -36,10 +48,12 @@ describe Prawn::SVG::Document do
|
|
36
48
|
let(:svg) { 'some_file.svg' }
|
37
49
|
|
38
50
|
it "raises an exception letting them know what they've done" do
|
51
|
+
message = "The data supplied is not a valid SVG document. It looks like you've supplied a filename " \
|
52
|
+
'instead; use File.read(filename) to get the data from the file before you pass it to prawn-svg.'
|
53
|
+
|
39
54
|
expect do
|
40
55
|
Prawn::SVG::Document.new(svg, bounds, options)
|
41
|
-
end.to raise_error Prawn::SVG::Document::InvalidSVGData,
|
42
|
-
"The data supplied is not a valid SVG document. It looks like you've supplied a filename instead; use IO.read(filename) to get the data before you pass it to prawn-svg."
|
56
|
+
end.to raise_error Prawn::SVG::Document::InvalidSVGData, /\A#{Regexp.escape(message)}/
|
43
57
|
end
|
44
58
|
end
|
45
59
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: prawn-svg
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.36.
|
4
|
+
version: 0.36.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mog Nesbitt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2025-01-
|
11
|
+
date: 2025-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: css_parser
|