diff options
-rw-r--r-- | include/serd/serd.h | 6 | ||||
-rw-r--r-- | src/env.c | 12 | ||||
-rw-r--r-- | test/test_env.c | 5 |
3 files changed, 20 insertions, 3 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h index 68443304..fcba2ddf 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -684,7 +684,7 @@ serd_env_set_prefix_from_strings(SerdEnv* SERD_NONNULL env, /// Qualify `uri` into a CURIE if possible SERD_API bool -serd_env_qualify(const SerdEnv* SERD_NONNULL env, +serd_env_qualify(const SerdEnv* SERD_NULLABLE env, const SerdNode* SERD_NONNULL uri, SerdNode* SERD_NONNULL prefix, SerdChunk* SERD_NONNULL suffix); @@ -697,7 +697,7 @@ serd_env_qualify(const SerdEnv* SERD_NONNULL env, */ SERD_API SerdStatus -serd_env_expand(const SerdEnv* SERD_NONNULL env, +serd_env_expand(const SerdEnv* SERD_NULLABLE env, const SerdNode* SERD_NONNULL curie, SerdChunk* SERD_NONNULL uri_prefix, SerdChunk* SERD_NONNULL uri_suffix); @@ -709,7 +709,7 @@ serd_env_expand(const SerdEnv* SERD_NONNULL env, */ SERD_API SerdNode -serd_env_expand_node(const SerdEnv* SERD_NONNULL env, +serd_env_expand_node(const SerdEnv* SERD_NULLABLE env, const SerdNode* SERD_NONNULL node); /// Call `func` for each prefix defined in `env` @@ -179,6 +179,10 @@ serd_env_qualify(const SerdEnv* const env, SerdNode* const prefix, SerdChunk* const suffix) { + if (!env) { + return false; + } + for (size_t i = 0; i < env->n_prefixes; ++i) { const SerdNode* const prefix_uri = &env->prefixes[i].uri; if (uri->n_bytes >= prefix_uri->n_bytes) { @@ -201,6 +205,10 @@ serd_env_expand(const SerdEnv* const env, SerdChunk* const uri_prefix, SerdChunk* const uri_suffix) { + if (!env) { + return SERD_ERR_BAD_CURIE; + } + const uint8_t* const colon = (const uint8_t*)memchr(curie->buf, ':', curie->n_bytes + 1); if (curie->type != SERD_CURIE || !colon) { @@ -222,6 +230,10 @@ serd_env_expand(const SerdEnv* const env, SerdNode serd_env_expand_node(const SerdEnv* const env, const SerdNode* const node) { + if (!env) { + return SERD_NODE_NULL; + } + switch (node->type) { case SERD_NOTHING: case SERD_LITERAL: diff --git a/test/test_env.c b/test/test_env.c index b25bd9e2..48bc6c9b 100644 --- a/test/test_env.c +++ b/test/test_env.c @@ -50,8 +50,13 @@ test_env(void) SerdChunk prefix; SerdChunk suffix; + assert(!serd_env_qualify(NULL, &u, &u, &suffix)); + assert(serd_env_expand(NULL, &c, &prefix, &suffix)); assert(serd_env_expand(env, &b, &prefix, &suffix)); + SerdNode nxnode = serd_env_expand_node(NULL, &c); + assert(serd_node_equals(&nxnode, &SERD_NODE_NULL)); + SerdNode xnode = serd_env_expand_node(env, &SERD_NODE_NULL); assert(serd_node_equals(&xnode, &SERD_NODE_NULL)); |