aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/env.c7
-rw-r--r--src/writer.c29
-rw-r--r--test/test_env.c2
3 files changed, 22 insertions, 16 deletions
diff --git a/src/env.c b/src/env.c
index 97bccfba..9a3d2ea5 100644
--- a/src/env.c
+++ b/src/env.c
@@ -25,8 +25,11 @@ SerdEnv*
serd_env_new(const SerdNode* const base_uri)
{
SerdEnv* env = (SerdEnv*)calloc(1, sizeof(struct SerdEnvImpl));
- if (env && base_uri) {
- serd_env_set_base_uri(env, base_uri);
+ if (env && base_uri && base_uri->type != SERD_NOTHING) {
+ if (serd_env_set_base_uri(env, base_uri)) {
+ free(env);
+ return NULL;
+ }
}
return env;
diff --git a/src/writer.c b/src/writer.c
index 26ed01c0..d2609cf5 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -1010,23 +1010,24 @@ serd_writer_chop_blank_prefix(SerdWriter* writer, const uint8_t* prefix)
SerdStatus
serd_writer_set_base_uri(SerdWriter* writer, const SerdNode* uri)
{
- if (!serd_env_set_base_uri(writer->env, uri)) {
- serd_env_get_base_uri(writer->env, &writer->base_uri);
+ const SerdStatus st = serd_env_set_base_uri(writer->env, uri);
+ if (st) {
+ return st;
+ }
- if (writer->syntax == SERD_TURTLE || writer->syntax == SERD_TRIG) {
- if (writer->context.graph.type || writer->context.subject.type) {
- sink(" .\n\n", 4, writer);
- reset_context(writer, true);
- }
- sink("@base <", 7, writer);
- sink(uri->buf, uri->n_bytes, writer);
- sink("> .\n", 4, writer);
+ serd_env_get_base_uri(writer->env, &writer->base_uri);
+
+ if (writer->syntax == SERD_TURTLE || writer->syntax == SERD_TRIG) {
+ if (writer->context.graph.type || writer->context.subject.type) {
+ sink(" .\n\n", 4, writer);
+ reset_context(writer, true);
}
- writer->indent = 0;
- return reset_context(writer, true);
+ sink("@base <", 7, writer);
+ sink(uri->buf, uri->n_bytes, writer);
+ sink("> .\n", 4, writer);
}
-
- return SERD_ERR_UNKNOWN;
+ writer->indent = 0;
+ return reset_context(writer, true);
}
SerdStatus
diff --git a/test/test_env.c b/test/test_env.c
index dd8660dc..1de075f3 100644
--- a/test/test_env.c
+++ b/test/test_env.c
@@ -64,6 +64,8 @@ test_env(void)
const SerdNode lit = serd_node_from_string(SERD_LITERAL, USTR("hello"));
assert(serd_env_set_prefix(env, &b, &lit));
+ assert(!serd_env_new(&lit));
+
const SerdNode blank = serd_node_from_string(SERD_BLANK, USTR("b1"));
const SerdNode xblank = serd_env_expand_node(env, &blank);
assert(serd_node_equals(&xblank, &SERD_NODE_NULL));