From 6d2e90e7e927b7a633ae9b1250c1bafc14d69674 Mon Sep 17 00:00:00 2001 From: David Robillard Date: Tue, 6 Mar 2018 20:51:09 -0500 Subject: Refuse to write relative URIs to NTriples or NQuads --- src/writer.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'src/writer.c') 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( -- cgit v1.2.1