aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2018-12-26 20:08:31 -0500
committerDavid Robillard <d@drobilla.net>2020-10-27 13:13:58 +0100
commit8f1a097f5140155804109154cc4b660efd21f3f0 (patch)
tree67dc4a51df51d2504f9b505aa476f57050c83b50
parent6133cdbc7d1615de2bfc2ee9f8082a09890bd72b (diff)
downloadserd-8f1a097f5140155804109154cc4b660efd21f3f0.tar.gz
serd-8f1a097f5140155804109154cc4b660efd21f3f0.tar.bz2
serd-8f1a097f5140155804109154cc4b660efd21f3f0.zip
Ensure serd_new_resolved_uri returns an absolute URI or NULL
-rw-r--r--src/env.c5
-rw-r--r--src/node.c16
-rw-r--r--tests/env_test.c4
3 files changed, 17 insertions, 8 deletions
diff --git a/src/env.c b/src/env.c
index 6828a0fd..49a8f370 100644
--- a/src/env.c
+++ b/src/env.c
@@ -123,11 +123,10 @@ serd_env_set_base_uri(SerdEnv* env,
SerdNode* base_uri_node = serd_new_resolved_uri_i(
serd_node_string(uri), &env->base_uri);
- SerdURI base_uri;
- serd_uri_parse(serd_node_string(base_uri_node), &base_uri);
-
if (base_uri_node) {
// Replace the current base URI
+ SerdURI base_uri;
+ serd_uri_parse(serd_node_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;
diff --git a/src/node.c b/src/node.c
index 7a1625f4..98585178 100644
--- a/src/node.c
+++ b/src/node.c
@@ -425,14 +425,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_string(result))) {
+ serd_node_free(result);
+ return NULL;
+ }
+
+ return result;
}
static inline bool
diff --git a/tests/env_test.c b/tests/env_test.c
index 25164701..d80eb1f8 100644
--- a/tests/env_test.c
+++ b/tests/env_test.c
@@ -39,6 +39,7 @@ test_env(void)
SerdNode* hello = serd_new_string("hello\"");
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");
@@ -47,7 +48,7 @@ test_env(void)
assert(!serd_env_base_uri(env));
assert(serd_env_set_base_uri(env, NULL));
- assert(!serd_env_base_uri(env));
+ assert(serd_env_set_base_uri(env, empty));
assert(serd_env_set_base_uri(env, hello));
assert(!serd_env_base_uri(env));
@@ -115,6 +116,7 @@ test_env(void)
serd_node_free(qualified);
serd_node_free(foo_c);
+ serd_node_free(empty);
serd_node_free(foo_u);
serd_node_free(lit);
serd_node_free(b);