aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2023-04-03 10:49:04 -0400
committerDavid Robillard <d@drobilla.net>2023-04-06 07:19:10 -0400
commite3fd76d4e5beb8596be651b41be730f62cfdc9d0 (patch)
tree2c55db64b3a2d0387173b7a210b3065247702018
parent9910494d7bb417fb75f1c99b65f9956d14184059 (diff)
downloadserd-e3fd76d4e5beb8596be651b41be730f62cfdc9d0.tar.gz
serd-e3fd76d4e5beb8596be651b41be730f62cfdc9d0.tar.bz2
serd-e3fd76d4e5beb8596be651b41be730f62cfdc9d0.zip
Make URI writing stricter by default
-rw-r--r--NEWS3
-rw-r--r--doc/serdi.14
-rw-r--r--src/serdi.c2
-rw-r--r--src/writer.c17
-rw-r--r--test/extra/bad/manifest.ttl30
-rw-r--r--test/meson.build10
6 files changed, 55 insertions, 11 deletions
diff --git a/NEWS b/NEWS
index a2f515a8..cf4c0008 100644
--- a/NEWS
+++ b/NEWS
@@ -19,12 +19,13 @@ serd (0.31.1) unstable; urgency=medium
* Improve TriG pretty-printing and remove trailing newlines
* Improve serdi man page
* Improve writer error handling
+ * Make URI writing stricter by default
* Override pkg-config dependency within meson
* Replace duplicated dox_to_sphinx script with sphinxygen dependency
* Test header for warnings more strictly
* Update standard test suites
- -- David Robillard <d@drobilla.net> Mon, 03 Apr 2023 12:55:38 +0000
+ -- David Robillard <d@drobilla.net> Mon, 03 Apr 2023 14:48:40 +0000
serd (0.30.16) stable; urgency=medium
diff --git a/doc/serdi.1 b/doc/serdi.1
index 5b76b1b8..782cfc23 100644
--- a/doc/serdi.1
+++ b/doc/serdi.1
@@ -58,7 +58,9 @@ Eat input one character at a time, rather than a page at a time which is the def
This is useful when reading from a pipe since output will be generated immediately as input arrives, rather than waiting until an entire page of input has arrived.
With this option serdi uses one page less memory, but will likely be significantly slower.
.It Fl f
-Keep full URIs in input (don't qualify with namespace prefixes or make URIs relative).
+Fast and loose URI mode:
+preserve full URIs (without qualifying or making relative),
+and pass prefixed names through as-is.
.It Fl h
Print the command line options.
.It Fl i Ar syntax
diff --git a/src/serdi.c b/src/serdi.c
index 97e9bc22..d82198ad 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -89,7 +89,7 @@ print_usage(const char* const name, const bool error)
" -b Write output in blocks for performance.\n"
" -c PREFIX Chop PREFIX from matching blank node IDs.\n"
" -e Eat input one character at a time.\n"
- " -f Keep full URIs in input (don't qualify).\n"
+ " -f Fast and loose URI pass-through.\n"
" -h Display this help and exit.\n"
" -i SYNTAX Input syntax: turtle/ntriples/trig/nquads.\n"
" -l Lax (non-strict) parsing.\n"
diff --git a/src/writer.c b/src/writer.c
index fcd0e1dc..8fdca6f9 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -677,19 +677,22 @@ write_curie(SerdWriter* const writer,
SerdChunk suffix = {NULL, 0};
SerdStatus st = SERD_SUCCESS;
- switch (writer->syntax) {
- case SERD_NTRIPLES:
- case SERD_NQUADS:
+ // In fast-and-loose Turtle/TriG mode CURIEs are simply passed through
+ const bool fast =
+ !(writer->style & (SERD_STYLE_CURIED | SERD_STYLE_RESOLVED));
+
+ if (!supports_abbrev(writer) || !fast) {
if ((st = serd_env_expand(writer->env, node, &prefix, &suffix))) {
return w_err(writer, st, "undefined namespace prefix '%s'\n", node->buf);
}
+ }
+
+ if (!supports_abbrev(writer)) {
TRY(st, esink("<", 1, writer));
write_uri(writer, prefix.buf, prefix.len);
write_uri(writer, suffix.buf, suffix.len);
TRY(st, esink(">", 1, writer));
- break;
- case SERD_TURTLE:
- case SERD_TRIG:
+ } else {
if (is_inline_start(writer, field, flags)) {
++writer->indent;
TRY(st, write_sep(writer, SEP_ANON_BEGIN));
@@ -702,7 +705,7 @@ write_curie(SerdWriter* const writer,
}
}
- return SERD_SUCCESS;
+ return st;
}
SERD_NODISCARD static SerdStatus
diff --git a/test/extra/bad/manifest.ttl b/test/extra/bad/manifest.ttl
index 10130df8..0ea3ccac 100644
--- a/test/extra/bad/manifest.ttl
+++ b/test/extra/bad/manifest.ttl
@@ -6,6 +6,7 @@
a mf:Manifest ;
rdfs:comment "Serd bad (negative) test suite" ;
mf:entries (
+ <#bad-a-object>
<#bad-a-subject>
<#bad-base>
<#bad-blank>
@@ -43,6 +44,8 @@
<#bad-equivalence>
<#bad-escape>
<#bad-ext-namedblank-op>
+ <#bad-false-predicate>
+ <#bad-false-subject>
<#bad-forAll>
<#bad-forSome>
<#bad-graph-blank-label>
@@ -76,6 +79,8 @@
<#bad-semicolon-after-subject>
<#bad-string>
<#bad-subject>
+ <#bad-true-predicate>
+ <#bad-true-subject>
<#bad-uri-escape>
<#bad-uri-scheme>
<#bad-uri-scheme-start>
@@ -83,6 +88,11 @@
<#bad-verb>
) .
+<#bad-a-object>
+ a rdft:TestTurtleNegativeSyntax ;
+ mf:action <bad-a-object.ttl> ;
+ mf:name "bad-a-object" .
+
<#bad-a-subject>
a rdft:TestTurtleNegativeSyntax ;
mf:action <bad-a-subject.ttl> ;
@@ -268,6 +278,16 @@
mf:action <bad-ext-namedblank-op.ttl> ;
mf:name "bad-ext-namedblank-op" .
+<#bad-false-predicate>
+ a rdft:TestTurtleNegativeSyntax ;
+ mf:action <bad-false-predicate.ttl> ;
+ mf:name "bad-false-predicate" .
+
+<#bad-false-subject>
+ a rdft:TestTurtleNegativeSyntax ;
+ mf:action <bad-false-subject.ttl> ;
+ mf:name "bad-false-subject" .
+
<#bad-forAll>
a rdft:TestTurtleNegativeSyntax ;
mf:action <bad-forAll.ttl> ;
@@ -433,6 +453,16 @@
mf:action <bad-subject.ttl> ;
mf:name "bad-subject" .
+<#bad-true-predicate>
+ a rdft:TestTurtleNegativeSyntax ;
+ mf:action <bad-true-predicate.ttl> ;
+ mf:name "bad-true-predicate" .
+
+<#bad-true-subject>
+ a rdft:TestTurtleNegativeSyntax ;
+ mf:action <bad-true-subject.ttl> ;
+ mf:name "bad-true-subject" .
+
<#bad-uri-escape>
a rdft:TestTurtleNegativeSyntax ;
mf:action <bad-uri-escape.ttl> ;
diff --git a/test/meson.build b/test/meson.build
index c55f2c5d..0502e833 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -239,7 +239,7 @@ test_suites = {
],
'trig': [
files('w3c/trig/manifest.ttl'), ns_w3 + 'TriGTests/',
- '--', '-a', '-f', '-i', 'TriG',
+ '--', '-a', '-i', 'TriG',
],
'turtle': [
files('w3c/turtle/manifest.ttl'), ns_w3 + 'TurtleTests/',
@@ -252,6 +252,10 @@ test_suites = {
'bad': [
files('extra/bad/manifest.ttl'), ns_serdtest + 'bad/',
],
+ 'bad_turtle': [
+ files('extra/bad/manifest.ttl'), ns_serdtest + 'bad/',
+ '--', '-o', 'turtle',
+ ],
'big': [
files('extra/big/manifest.ttl'), ns_serdtest + 'big/',
],
@@ -259,6 +263,10 @@ test_suites = {
files('extra/good/manifest.ttl'), ns_serdtest + 'good/',
'--', '-b',
],
+ 'fast': [
+ files('extra/good/manifest.ttl'), ns_serdtest + 'good/',
+ '--', '-f',
+ ],
'full': [
files('extra/full/manifest.ttl'), ns_serdtest + 'full/',
'--', '-f',