Skip to content

Commit 5aec3cf

Browse files
committed
Correct a bug when reading ntriples data that prevent to have values with "VERSION"
1 parent d6dd27d commit 5aec3cf

2 files changed

Lines changed: 32 additions & 1 deletion

File tree

lib/rdf/ntriples/reader.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class Reader < RDF::Reader
9292

9393
# LANGTAG is deprecated
9494
LANGTAG = LANG_DIR
95-
RDF_VERSION = /VERSION/.freeze
95+
RDF_VERSION = /\A\s*VERSION/.freeze
9696

9797
##
9898
# Reconstructs an RDF value from its serialized N-Triples

spec/ntriples_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,37 @@
373373
tt = reader.parse_literal("<<(<https://rubygems.org/gems/rdf> <http://purl.org/dc/terms/creator> <http://ar.to/#self>)>>")
374374
expect(tt).to be_nil
375375
end
376+
context 'should parse values containing VERSION' do
377+
let(:predicate) { "https://www.ica.org/standards/RiC/ontology#textualValue" }
378+
let(:subject_uri) { "https://repository2-onsitedemo.docuteam.ch/fcrepo/rest/mandant1/rr_test#id" }
379+
380+
it "successfully parses a literal containing the word 'VERSION'" do
381+
triple_line = "<#{subject_uri}> <#{predicate}> \"test_VERSION_test\" .\n"
382+
statements = []
383+
reader = RDF::NTriples::Reader.new(triple_line)
384+
385+
expect {
386+
reader.each_statement { |s| statements << s }
387+
}.not_to raise_error
388+
389+
expect(statements.size).to eq(1)
390+
expect(statements.first.object.to_s).to eq("test_VERSION_test")
391+
end
392+
393+
it "successfully parses a URI containing the word 'VERSION'" do
394+
uri_with_version = "https://example.org/VERSION_check"
395+
triple_line = "<#{uri_with_version}> <#{predicate}> \"plain_value\" .\n"
396+
397+
statements = []
398+
reader = RDF::NTriples::Reader.new(triple_line)
399+
400+
expect {
401+
reader.each_statement { |s| statements << s }
402+
}.not_to raise_error
403+
404+
expect(statements.first.subject.to_s).to eq(uri_with_version)
405+
end
406+
end
376407

377408
describe "literal encodings" do
378409
{

0 commit comments

Comments
 (0)