Skip to content

crash in Turtle-related serializers due to malformed rdf:XMLLiteral datatype #3

@doriantaylor

Description

@doriantaylor

I got a crash when trying to serialize a graph containing rdf:XMLLiteral terms. I went and pulled them out of the store, and the few terms in the repository that are XML literals, the datatype is a String:

[11] pry(#<Intertwingler::CLI>)> lol.dump :turtle
NoMethodError: undefined method `invalid?' for "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral":String (NoMethodError)

      return false if datatype? && datatype.invalid?
                                           ^^^^^^^^^
from /var/lib/gems/3.2.0/gems/rdf-3.3.2/lib/rdf/model/literal.rb:447:in `valid?'

I have tracked down the culprit; looks like and it's ostensibly specific to XML literals:

require 'rdf'
require 'rdf/ntriples'
require 'rdf/xsd'

test = RDF::NTriples::Reader.parse_object('"<strong xmlns=\"http://www.w3.org/1999/xhtml\">hi</strong>"^^<http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral>')

test.datatype
# "http://www.w3.org/1999/02/22-rdf-syntax-ns#XMLLiteral"

Now: run this code again, commenting out require 'rdf/xsd'.

It looks like the RDF::XSD constructor does not coerce the datatype:

@datatype = datatype || DATATYPE

…probably just putting RDF::URI(datatype) would fix this bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions