ruby-rdf / rdf-turtle

Turtle reader/writer for Ruby
http://rubygems.org/gems/rdf-turtle
The Unlicense
31 stars 9 forks source link

Turtle serialization of boolean values should have extra whitespace - can lead to parsing errors #20

Closed joepio closed 2 years ago

joepio commented 2 years ago

When serialising a boolean with Turtle, there is no spacebar behind the boolean. This can (sometimes) lead to parsing errors. At least, we had issues when parsing this with the PHP library easy RDF. It's not entirely clear whether it is required to have a spacebar behind a boolean value from the spec, but in all examples, there is a whitespace.

How rdf-turtle serialises (no space behind boolean)

<http://somecountry.example/census2007> <http://example.org/stats/islandlocked>  false.

What most will expect (one whitespace behind boolean)

<http://somecountry.example/census2007> <http://example.org/stats/islandlocked>  false .
gkellogg commented 2 years ago

While the EBNF grammar typically does not require any white space, the rdf-turtle writer pretty much always writes it when serializing, IIRC. Do you have a test class you can provide that demonstrates the behavior? A white space is typically not used when writing a “,” or “;”, but is before “.” as a matter of my particular style. In the wild, both behaviors are common.

gkellogg commented 2 years ago

Looking more at the example you referenced, the processing problem with easyRdf seems to be with true;, not true.. Both are perfectly legal, and a parser would typically tokenize the input stream, and recognize true as a token, thus not need whitespace to separate these lexical elements.

This gem does, indeed, output statements such as <> dc:title true; dx:offer "foo" . (although using true for the value of dc:title is suspect), and other serializers will do the same thing. So, I suggest that the issue lies with easyRdf.