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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b833a9af0fae6fd2934c6b5ef37bd6d6d90aba36fa9a161520ac6a9a1c19f9db
4
- data.tar.gz: 550aa711e413cac65e8af39f029096e3606f84a852b982729ca0252e758805ac
3
+ metadata.gz: 28ccc4cc947f9d497484516d673f66098fd4624e11aba0035afc4d4373ec27cc
4
+ data.tar.gz: 19344cb3568acff4b85de31d199024070dacaa10eeaf4305d9d35265a547dbda
5
5
  SHA512:
6
- metadata.gz: 9a522f7b4aa8f713fc453cc3d6061968fce1a28ab60e58f6c321b92979bcb909748a81b8c9cb9a373f918d152e969ea7d0974afd975c8fba7ae70c03cec18a25
7
- data.tar.gz: 537a912b7daab1581662cabfc5de5776ebe771d15e448e99a7c7d6125eb29644bbc40de6508429f5a3451f16ebb226f53402320ef4430118b16d05913cd3ede4
6
+ metadata.gz: 535e9463f1577596e42889fec04c0d0a41cfb30ee6cd0c293c4a028987bde0bf607c482767d1d916445ad7042d14c653a696e2da9c096ff8e40dc6ccc3a69ae6
7
+ data.tar.gz: 929c06b75e31fd7314b5ade1ad86f00a6b4d8b98fceff0f66672cf7f1a0b1b70cf75fc28461042c8f91915d43bc5778ea27e49d6aa00aa280037835f9683db8c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- prawn-svg (0.36.0)
4
+ prawn-svg (0.36.1)
5
5
  css_parser (~> 1.6)
6
6
  matrix (~> 0.4.2)
7
7
  prawn (>= 0.11.1, < 3)
@@ -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
- @root = nil
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
@@ -1,5 +1,5 @@
1
1
  module Prawn
2
2
  module SVG
3
- VERSION = '0.36.0'.freeze
3
+ VERSION = '0.36.1'.freeze
4
4
  end
5
5
  end
@@ -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 'raises an exception' do
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, 'The data supplied is not a valid SVG document.'
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.0
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-05 00:00:00.000000000 Z
11
+ date: 2025-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: css_parser