Repository navigation
Closed
Labels
enhancementNew feature or request
Description
Symptom
Today's Turtle output (e.g. https://test.solid.social/profile/card.jsonld with Accept: text/turtle) packs ; and . directly against the previous token:
<...#me> a foaf:Person, schema:Person;
foaf:name "test";
pim:storage <https://test.solid.social/>.
<...#nostr-key-1> a <https://www.w3.org/ns/cid/v1#Multikey>;
<https://www.w3.org/ns/cid/v1#controller> <...#me>;
<https://www.w3.org/ns/cid/v1#publicKeyMultibase> "fe70102de7ec...".A more typical/canonical-leaning style separates the statement terminators from the previous token by a space:
<...#me> a foaf:Person, schema:Person ;
foaf:name "test" ;
pim:storage <https://test.solid.social/> .
<...#nostr-key-1> a <https://www.w3.org/ns/cid/v1#Multikey> ;
<https://www.w3.org/ns/cid/v1#controller> <...#me> ;
<https://www.w3.org/ns/cid/v1#publicKeyMultibase> "fe70102de7ec..." .Status of "canonical form" for Turtle
There is no formally W3C-defined canonical Turtle. RDF Dataset Canonicalization (RDC-1.0) operates on N-Quads, not Turtle. So strictly speaking, both forms are spec-conformant Turtle.
However, the spaced form is widely treated as the "pretty" / preferred style:
- W3C Turtle 1.1 spec examples consistently use a space before
;and. - Apache Jena's RIOT Turtle writer emits the spaced form
- Most hand-written Turtle in the Solid / Linked Data ecosystem uses the spaced form
- It improves human readability (the terminator is visually separable from the value) and reduces ambiguity for naive line-counters
The current N3.js default packs them. JSS uses N3.js (new Writer({...})) — see src/rdf/turtle.js:72.
What to investigate
- Whether N3.js's
Writerexposes a config option (spaceBeforeTerminator,pretty, etc.) for this. If it does, flip the option in our usage. - If not, evaluate whether a small post-processing pass on the writer's output (regex
/([^\s])([;.])(\s|$)/g→$1 $2$3, with care around literals containing;or.) is the right approach. Note the literal-safety concern is real —"foo;bar"must not become"foo ;bar". - Check whether any existing test depends on the no-space form (it shouldn't — Turtle parsers must accept both — but a snapshot-style test might).
Acceptance
After the change, curl -H 'Accept: text/turtle' <profile> emits:
- A space before every
;that terminates a predicate-list continuation - A space before every
.that terminates a triple - Existing parsers (N3.js, Jena, rdflib, etc.) round-trip unchanged
- Existing JSS Turtle tests still pass (or are minimally updated to match the new style)
Refs
- W3C Turtle 1.1 — spec examples use the spaced form
- Apache Jena RIOT Turtle output style — same
- N3.js writer used at
src/rdf/turtle.js:72 - Sibling Turtle issues: rdf/turtle: JSON-LD @context array form not handled — locally-resolvable contexts only #389 (array-context), rdf/turtle: emit @type:'@json' literal values (rdf:JSON datatype) — Phase B blocker for CID publicKeyJwk #390 (
@type: '@json'), rdf/turtle: nested verificationMethod objects dropped from Turtle output #415/rdf/turtle: accept JSON-LD id/type aliases on nested objects (#415) #416 (nested VM), Profile emits bare 'Multikey' type — resolves to <pod>/profile/Multikey instead of cid:Multikey #417 (Multikey class IRI) — all about making JSS's Turtle output spec-correct + interop-friendly
Metadata
Metadata
Assignees
Labels
enhancementNew feature or request
Activity
Address copilot pass 1 on #420 — assert by value, not by lexical form
Address copilot pass 3 on #420 — require literal space, not any white…
rdf/turtle: emit a space before ';' and '.' terminators (#419) (#420)