Skip to content

Commit 409762d

Browse files
committed
If validating, only return valid triples from N-Triples reader.
1 parent 6876b76 commit 409762d

2 files changed

Lines changed: 5 additions & 3 deletions

File tree

lib/rdf/ntriples/reader.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ def read_triple
230230
if validate? && !read_eos
231231
log_error("Expected end of statement (found: #{current_line.inspect})", lineno: lineno, exception: RDF::ReaderError)
232232
end
233-
return [subject, predicate, object]
233+
spo = [subject, predicate, object]
234+
# Only return valid triples if validating
235+
return spo if !validate? || spo.all?(&:valid?)
234236
end
235237
rescue RDF::ReaderError => e
236238
@line = line # this allows #read_value to work

lib/rdf/reader.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ def each_statement(&block)
444444
begin
445445
loop do
446446
st = read_statement
447-
block.call(st)
447+
block.call(st) unless st.nil?
448448
end
449449
rescue EOFError
450450
rewind rescue nil
@@ -481,7 +481,7 @@ def each_triple(&block)
481481
begin
482482
loop do
483483
triple = read_triple
484-
block.call(*triple)
484+
block.call(*triple) unless triple.nil?
485485
end
486486
rescue EOFError
487487
rewind rescue nil

0 commit comments

Comments
 (0)