diff options
author | David Robillard <d@drobilla.net> | 2018-03-06 20:51:09 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2018-03-06 20:51:09 -0500 |
commit | 6d2e90e7e927b7a633ae9b1250c1bafc14d69674 (patch) | |
tree | 72f9861bc158e1e0c73ce27ef055b987f2a7ec72 /src | |
parent | ec107729b07254bd9cc7ce0825af9867e130b4b6 (diff) | |
download | serd-absolute-base-uri.tar.gz serd-absolute-base-uri.tar.bz2 serd-absolute-base-uri.zip |
Refuse to write relative URIs to NTriples or NQuadsabsolute-base-uri
Diffstat (limited to 'src')
-rw-r--r-- | src/writer.c | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/writer.c b/src/writer.c index 64b99076..5415781e 100644 --- a/src/writer.c +++ b/src/writer.c @@ -477,7 +477,10 @@ write_uri_node(SerdWriter* const writer, sink("== ", 3, writer); } - const bool has_scheme = serd_uri_string_has_scheme(node->buf); + const bool has_scheme = serd_uri_string_has_scheme(node->buf); + const bool supports_rel = (writer->syntax != SERD_NTRIPLES && + writer->syntax != SERD_NQUADS); + if (field == FIELD_PREDICATE && supports_abbrev(writer) && !strcmp((const char*)node->buf, NS_RDF "type")) { return sink("a", 1, writer) == 1; @@ -501,11 +504,15 @@ write_uri_node(SerdWriter* const writer, return false; } serd_uri_resolve(&uri, &in_base_uri, &abs_uri); + if (!abs_uri.scheme.len && !supports_rel) { + w_err(writer, SERD_ERR_BAD_SYNTAX, + "unable to write relative URI `%s'\n", node->buf); + return false; + } + bool rooted = uri_is_under(&writer->base_uri, &writer->root_uri); SerdURI* root = rooted ? &writer->root_uri : & writer->base_uri; - if (!uri_is_under(&abs_uri, root) || - writer->syntax == SERD_NTRIPLES || - writer->syntax == SERD_NQUADS) { + if (!uri_is_under(&abs_uri, root) || !supports_rel) { serd_uri_serialise(&abs_uri, uri_sink, writer); } else { serd_uri_serialise_relative( |