File tree Expand file tree Collapse file tree 2 files changed +40
-2
lines changed Expand file tree Collapse file tree 2 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -63,8 +63,13 @@ def find_source block, uri
63
63
checked = [ ]
64
64
65
65
resources = block . document . attr 'resources'
66
- if resources
67
- to_check += CSV . parse_line ( resources )
66
+ if resources and not resources . empty?
67
+ begin
68
+ to_check += CSV . parse_line ( resources )
69
+ rescue CSV ::MalformedCSVError => error
70
+ logger . error message_with_context "Error loading [resources]: #{ error } " ,
71
+ :source_location => block . source_location
72
+ end
68
73
end
69
74
70
75
while ( dir = to_check . shift )
Original file line number Diff line number Diff line change @@ -163,6 +163,39 @@ def copy_attributes copied
163
163
}
164
164
end
165
165
166
+ it "doesn't mind an empty resources attribute" do
167
+ copied = [ ]
168
+ attributes = copy_attributes copied
169
+ attributes [ 'resources' ] = ''
170
+ input = <<~ASCIIDOC
171
+ == Example
172
+ image::example1.png[]
173
+ ASCIIDOC
174
+ convert input , attributes ,
175
+ eq ( "INFO: <stdin>: line 2: copying #{ spec_dir } /resources/copy_images/example1.png" )
176
+ expect ( copied ) . to eq ( [
177
+ [ "example1.png" , "#{ spec_dir } /resources/copy_images/example1.png" ]
178
+ ] )
179
+ end
180
+
181
+ it "has a nice error message if resources is invalid CSV" do
182
+ copied = [ ]
183
+ attributes = copy_attributes copied
184
+ attributes [ 'resources' ] = '"'
185
+ input = <<~ASCIIDOC
186
+ == Example
187
+ image::example1.png[]
188
+ ASCIIDOC
189
+ expected_warnings = <<~LOG
190
+ ERROR: <stdin>: line 2: Error loading [resources]: Unclosed quoted field on line 1.
191
+ INFO: <stdin>: line 2: copying #{ spec_dir } /resources/copy_images/example1.png
192
+ LOG
193
+ convert input , attributes , eq ( expected_warnings . strip )
194
+ expect ( copied ) . to eq ( [
195
+ [ "example1.png" , "#{ spec_dir } /resources/copy_images/example1.png" ]
196
+ ] )
197
+ end
198
+
166
199
it "has a nice error message when it can't find a file with single valued resources attribute" do
167
200
Dir . mktmpdir { |tmp |
168
201
copied = [ ]
You can’t perform that action at this time.
0 commit comments