diff options
author | David Robillard <d@drobilla.net> | 2012-03-29 00:51:50 +0000 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2012-03-29 00:51:50 +0000 |
commit | 32da26f159e2d16218809ae3e2526ae85841787a (patch) | |
tree | 1e63acf057ef3a60760fbd85cc4e4a8c12ddc650 | |
parent | 75ad5aa2a14339a38ac6824f2039d551ab04457d (diff) | |
download | serd-32da26f159e2d16218809ae3e2526ae85841787a.tar.gz serd-32da26f159e2d16218809ae3e2526ae85841787a.tar.bz2 serd-32da26f159e2d16218809ae3e2526ae85841787a.zip |
Don't break relative URIs with up-references when parsing a document with no base URI.
git-svn-id: http://svn.drobilla.net/serd/trunk@342 490d8e77-9747-427b-9fa3-0b8f29cee8a0
-rw-r--r-- | src/serdi.c | 2 | ||||
-rw-r--r-- | src/uri.c | 14 | ||||
-rw-r--r-- | tests/test-uri.out | 1 | ||||
-rw-r--r-- | tests/test-uri.ttl | 1 |
4 files changed, 11 insertions, 7 deletions
diff --git a/src/serdi.c b/src/serdi.c index 0236156e..74a84992 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -164,7 +164,7 @@ main(int argc, char** argv) if (a < argc) { // Base URI given on command line base = serd_node_new_uri_from_string( (const uint8_t*)argv[a], NULL, &base_uri); - } else if (from_file) { // Use input file URI + } else if (from_file && in_fd != stdin) { // Use input file URI base = serd_node_new_file_uri(input, NULL, &base_uri, false); } @@ -327,6 +327,8 @@ merge(SerdChunk* base, SerdChunk* path) if (base->buf) { assert(base->len > 0); + assert(base->buf[0] == '/'); + // Find the up'th last slash const uint8_t* base_last = (base->buf + base->len - 1); ++up; @@ -337,12 +339,7 @@ merge(SerdChunk* base, SerdChunk* path) } while (up > 0 && (--base_last > base->buf)); // Set path prefix - if (*base_last == '/') { - base->len = base_last - base->buf + 1; - } else { - base->len = 0; - base->buf = NULL; - } + base->len = base_last - base->buf + 1; } // Set path suffix @@ -355,6 +352,11 @@ SERD_API void serd_uri_resolve(const SerdURI* r, const SerdURI* base, SerdURI* t) { + if (!base->scheme.len) { + *t = *r; // Don't resolve against non-absolute URIs + return; + } + t->path_base.buf = NULL; t->path_base.len = 0; if (r->scheme.len) { diff --git a/tests/test-uri.out b/tests/test-uri.out index 8fd5dd87..6c56f594 100644 --- a/tests/test-uri.out +++ b/tests/test-uri.out @@ -40,5 +40,6 @@ <http://A#afragment> <http://www.w3.org/2002/07/owl#sameAs> <http://A#afragment> . <http://a/b/c/d;p?aquery> <http://www.w3.org/2002/07/owl#sameAs> <http://a/b/c/d;p?aquery> . <http://a/b/c/d;p?q#afragment> <http://www.w3.org/2002/07/owl#sameAs> <http://a/b/c/d;p?q#afragment> . +<http://a/> <http://www.w3.org/2002/07/owl#sameAs> <http://a/> . <http://B/foo> <http://www.w3.org/2002/07/owl#sameAs> <http://B/foo> . <http://C/bar> <http://www.w3.org/2002/07/owl#sameAs> <http://C/bar> . diff --git a/tests/test-uri.ttl b/tests/test-uri.ttl index 8e4f5102..cf43a38b 100644 --- a/tests/test-uri.ttl +++ b/tests/test-uri.ttl @@ -57,6 +57,7 @@ <http://A#afragment> owl:sameAs <http://A#afragment> . <?aquery> owl:sameAs <http://a/b/c/d;p?aquery> . <#afragment> owl:sameAs <http://a/b/c/d;p?q#afragment> . +<../../../../../../> owl:sameAs <http://a/> . @base <http://B?bquery> . |