diff options
-rw-r--r-- | src/env.c | 5 | ||||
-rw-r--r-- | src/node.c | 16 | ||||
-rw-r--r-- | tests/serd_test.c | 4 |
3 files changed, 17 insertions, 8 deletions
@@ -120,11 +120,10 @@ serd_env_set_base_uri(SerdEnv* env, SerdNode* base_uri_node = serd_new_resolved_uri_i( serd_node_get_string(uri), &env->base_uri); - SerdURI base_uri; - serd_uri_parse(serd_node_get_string(base_uri_node), &base_uri); - if (base_uri_node) { // Replace the current base URI + SerdURI base_uri; + serd_uri_parse(serd_node_get_string(base_uri_node), &base_uri); serd_node_free(env->base_uri_node); env->base_uri_node = base_uri_node; env->base_uri = base_uri; @@ -359,14 +359,22 @@ serd_node_resolve(const SerdNode* node, const SerdNode* base) SerdNode* serd_new_resolved_uri_i(const char* str, const SerdURI* base) { + SerdNode* result = NULL; if (!str || str[0] == '\0') { // Empty URI => Base URI, or nothing if no base is given - return base ? serd_new_from_uri(base, NULL) : NULL; + result = base ? serd_new_from_uri(base, NULL) : NULL; + } else { + SerdURI uri; + serd_uri_parse(str, &uri); + result = serd_new_from_uri(&uri, base); } - SerdURI uri; - serd_uri_parse(str, &uri); - return serd_new_from_uri(&uri, base); + if (!serd_uri_string_has_scheme(serd_node_get_string(result))) { + serd_node_free(result); + return NULL; + } + + return result; } static inline bool diff --git a/tests/serd_test.c b/tests/serd_test.c index 513344a3..6486e0ba 100644 --- a/tests/serd_test.c +++ b/tests/serd_test.c @@ -411,6 +411,7 @@ main(void) SerdNode* eg = serd_new_uri("http://example.org/"); SerdNode* foo_u = serd_new_uri("http://example.org/foo"); + SerdNode* empty = serd_new_uri(""); SerdNode* foo_c = serd_new_curie("eg.2:foo"); SerdNode* b = serd_new_curie("invalid"); SerdNode* pre = serd_new_curie("eg.2"); @@ -419,7 +420,7 @@ main(void) assert(!serd_env_get_base_uri(env)); assert(serd_env_set_base_uri(env, NULL)); - assert(!serd_env_get_base_uri(env)); + assert(serd_env_set_base_uri(env, empty)); assert(serd_env_set_base_uri(env, hello)); assert(!serd_env_get_base_uri(env)); @@ -474,6 +475,7 @@ main(void) serd_node_free(qualified); serd_node_free(foo_c); + serd_node_free(empty); serd_node_free(foo_u); serd_node_free(b); serd_node_free(pre); |