diff options
author | David Robillard <d@drobilla.net> | 2025-02-25 08:57:57 -0500 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2025-03-16 20:22:36 -0400 |
commit | 5ecac71066475b2bb55758ae138afeebeaa5b948 (patch) | |
tree | 2bbf63c80c713420d846105ac9eae0753e39fc4e /src/writer.c | |
parent | eb7e973b25a8e5556b2f1175d8375e5e513ba664 (diff) | |
download | serd-5ecac71066475b2bb55758ae138afeebeaa5b948.tar.gz serd-5ecac71066475b2bb55758ae138afeebeaa5b948.tar.bz2 serd-5ecac71066475b2bb55758ae138afeebeaa5b948.zip |
Refuse to write incoherent statements
Diffstat (limited to 'src/writer.c')
-rw-r--r-- | src/writer.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/writer.c b/src/writer.c index f0a9ad16..ab237099 100644 --- a/src/writer.c +++ b/src/writer.c @@ -1,4 +1,4 @@ -// Copyright 2011-2023 David Robillard <d@drobilla.net> +// Copyright 2011-2025 David Robillard <d@drobilla.net> // SPDX-License-Identifier: ISC #include "attributes.h" @@ -926,10 +926,6 @@ serd_writer_write_statement(SerdWriter* const writer, SerdStatus st = SERD_SUCCESS; - if (!is_resource(subject) || !is_resource(predicate) || !object->buf) { - return SERD_ERR_BAD_ARG; - } - if ((flags & SERD_LIST_O_BEGIN) && !strcmp((const char*)object->buf, NS_RDF "nil")) { /* Tolerate LIST_O_BEGIN for "()" objects, even though it doesn't make @@ -938,6 +934,17 @@ serd_writer_write_statement(SerdWriter* const writer, flags &= (SerdStatementFlags)~SERD_LIST_O_BEGIN; } + // Refuse to write incoherent statements + if (!is_resource(subject) || !is_resource(predicate) || + object->type == SERD_NOTHING || !object->buf || + (datatype && datatype->buf && lang && lang->buf) || + ((flags & SERD_ANON_S_BEGIN) && (flags & SERD_LIST_S_BEGIN)) || + ((flags & SERD_EMPTY_S) && (flags & SERD_LIST_S_BEGIN)) || + ((flags & SERD_ANON_O_BEGIN) && (flags & SERD_LIST_O_BEGIN)) || + ((flags & SERD_EMPTY_O) && (flags & SERD_LIST_O_BEGIN))) { + return SERD_ERR_BAD_ARG; + } + // Simple case: write a line of NTriples or NQuads if (writer->syntax == SERD_NTRIPLES || writer->syntax == SERD_NQUADS) { TRY(st, write_node(writer, subject, NULL, NULL, FIELD_SUBJECT, flags)); |