Skip to content

SPARQLResultsTSVWriter writes naked/unquoted xsd:strings #5256

@jimsmart

Description

@jimsmart

Current Behavior

Literals of type xsd:string often get written out in SPARQL TSV results without quotes.

This is because of this section of code:

} else if (!label.isEmpty() && encoded.equals(label) && label.charAt(0) != '<' && label.charAt(0) != '_'

Expected Behavior

The spec for SPARQL Results TSV says:

4.2 Serializing RDF Terms

The SPARQL Results TSV Results Format serializes RDF terms in the results table by using the syntax that SPARQL [SPARQL11-QUERY] and Turtle [TURTLE] use.

IRIs enclosed in <...>, literals are enclosed with double quotes "..." or single quotes ' ...' with optional @lang or ^^ for datatype. The quotes around the lexical form is required.

So, according to this last sentence — plus the reference to Turtle just previous — in TSV SPARQL results, one would expect all xsd:string literals to be quoted, in all circumstances — and not just when they don't pass the conditions in line 204

Steps To Reproduce

From the workbench, execute a SPARQL insert like this:

INSERT DATA
{
  GRAPH <http://example/g> {
  <http://example/s1> <http://example/p1> "o3" .
  }
}

Then execute a query like this:

select ?o { ?s ?p ?o }

Then download the results as SPARQL/TSV, and view in a text editor, to see:

?o
o3

...the o3 there should be "o3".

Version

5.1.0

Are you interested in contributing a solution yourself?

None

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    specificationissues related to compliance to standards and external specs🐞 bugissue is a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions