Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SPARQLResultsTSVWriter writes naked/unquoted xsd:strings #5256

Open
jimsmart opened this issue Feb 24, 2025 · 4 comments
Open

SPARQLResultsTSVWriter writes naked/unquoted xsd:strings #5256

jimsmart opened this issue Feb 24, 2025 · 4 comments
Labels
🐞 bug issue is a bug specification issues related to compliance to standards and external specs

Comments

@jimsmart
Copy link

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

@jimsmart jimsmart added the 🐞 bug issue is a bug label Feb 24, 2025
@hmottestad hmottestad added the specification issues related to compliance to standards and external specs label Feb 25, 2025
hmottestad added a commit to hmottestad/rdf4j that referenced this issue Feb 27, 2025
Related to eclipse-rdf4j#5256

Update `SPARQLResultsTSVWriter` to ensure all `xsd:string` literals are quoted in SPARQL TSV results.

* Modify `writeLiteral` method to always quote `xsd:string` literals.
* Remove conditions that allowed `xsd:string` literals to be written without quotes.
* Ensure special characters in `xsd:string` literals are properly escaped using `encodeString` method.
* Update tests in `SPARQLTSVCustomTest` to verify correct quoting of `xsd:string` literals and proper escaping of special characters.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/eclipse-rdf4j/rdf4j/issues/5256?shareId=XXXX-XXXX-XXXX-XXXX).
hmottestad added a commit to hmottestad/rdf4j that referenced this issue Mar 14, 2025
Related to eclipse-rdf4j#5256

Update `SPARQLResultsTSVWriter` to ensure all `xsd:string` literals are quoted in SPARQL TSV results.

* Modify `writeLiteral` method to always quote `xsd:string` literals.
* Remove conditions that allowed `xsd:string` literals to be written without quotes.
* Ensure special characters in `xsd:string` literals are properly escaped using `encodeString` method.
* Update tests in `SPARQLTSVCustomTest` to verify correct quoting of `xsd:string` literals and proper escaping of special characters.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/eclipse-rdf4j/rdf4j/issues/5256?shareId=XXXX-XXXX-XXXX-XXXX).
@hmottestad
Copy link
Contributor

Can you test out #5262 to see if it fixes your issue?

@jimsmart
Copy link
Author

Thanks for your work on this.

Is there a downloadable binary I can test, please?

I'm running the SPARQL server, from the downloadable binary distribution — I'm not running it from source, and I don't have any kind of Java build process setup on my system, sorry!

@hmottestad
Copy link
Contributor

I can try to create one for you. Is it the big jar file or is it the war file?

@jimsmart
Copy link
Author

I use both rdf4j-server.war and rdf4j-workbench.war in my webapps folder.

I would imagine that I only need an updated copy of that first one though, the server itself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🐞 bug issue is a bug specification issues related to compliance to standards and external specs
Projects
None yet
Development

No branches or pull requests

2 participants