From 1cfecadf30286bb146a9f60154dc9d4e48f8d1cb Mon Sep 17 00:00:00 2001 From: David Robillard Date: Wed, 13 Jun 2018 17:11:13 -0400 Subject: Remove escape parameter from serd_new_file_uri Since characters are escaped because they are not valid characters in a URI, any use of this function without escaping is problematic at best. --- serd/serd.h | 7 +++---- src/node.c | 4 ++-- src/serdi.c | 2 +- tests/serd_test.c | 15 ++++++--------- 4 files changed, 12 insertions(+), 16 deletions(-) diff --git a/serd/serd.h b/serd/serd.h index eff91e17..4533c378 100644 --- a/serd/serd.h +++ b/serd/serd.h @@ -602,16 +602,15 @@ serd_node_resolve(const SerdNode* node, const SerdNode* base); /** Create a new file URI node from a file system path and optional hostname. - Backslashes in Windows paths will be converted and '%' will always be - percent encoded. If `escape` is true, all other invalid characters will be - percent encoded as well. + Backslashes in Windows paths will be converted, and other characters will be + percent encoded as necessary. If `path` is relative, `hostname` is ignored. If `out` is not NULL, it will be set to the parsed URI. */ SERD_API SerdNode* -serd_new_file_uri(const char* path, const char* hostname, bool escape); +serd_new_file_uri(const char* path, const char* hostname); /** Create a new URI from a string, relative to a base URI. diff --git a/src/node.c b/src/node.c index 65a87a8b..223598c4 100644 --- a/src/node.c +++ b/src/node.c @@ -389,7 +389,7 @@ is_uri_path_char(const char c) } SerdNode* -serd_new_file_uri(const char* path, const char* hostname, bool escape) +serd_new_file_uri(const char* path, const char* hostname) { const size_t path_len = strlen(path); const size_t hostname_len = hostname ? strlen(hostname) : 0; @@ -410,7 +410,7 @@ serd_new_file_uri(const char* path, const char* hostname, bool escape) serd_buffer_sink("/", 1, 1, &buffer); } else if (path[i] == '%') { serd_buffer_sink("%%", 1, 2, &buffer); - } else if (!escape || is_uri_path_char(path[i])) { + } else if (is_uri_path_char(path[i])) { serd_buffer_sink(path + i, 1, 1, &buffer); } else { char escape_str[4] = { '%', 0, 0, 0 }; diff --git a/src/serdi.c b/src/serdi.c index 03afee90..e2cdc0c1 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -199,7 +199,7 @@ main(int argc, char** argv) if (a < argc) { // Base URI given on command line base = serd_new_uri((const char*)argv[a]); } else if (!from_string && !from_stdin) { // Use input file URI - base = serd_new_file_uri(input, NULL, true); + base = serd_new_file_uri(input, NULL); } FILE* out_fd = stdout; diff --git a/tests/serd_test.c b/tests/serd_test.c index d4bb1e42..b8b35a0b 100644 --- a/tests/serd_test.c +++ b/tests/serd_test.c @@ -84,7 +84,6 @@ test_sink(void* handle, static int check_file_uri(const char* hostname, const char* path, - bool escape, const char* expected_uri, const char* expected_path) { @@ -92,7 +91,7 @@ check_file_uri(const char* hostname, expected_path = path; } - SerdNode* node = serd_new_file_uri(path, hostname, escape); + SerdNode* node = serd_new_file_uri(path, hostname); const char* node_str = serd_node_get_string(node); char* out_hostname = NULL; char* out_path = serd_file_uri_parse(node_str, &out_hostname); @@ -260,18 +259,16 @@ main(void) // Test file URI escaping and parsing - if (check_file_uri(NULL, "C:/My 100%", true, + if (check_file_uri(NULL, "C:/My 100%", "file:///C:/My%20100%%", NULL) || - check_file_uri("ahost", "C:\\Pointless Space", true, + check_file_uri("ahost", "C:\\Pointless Space", "file://ahost/C:/Pointless%20Space", "C:/Pointless Space") || - check_file_uri(NULL, "/foo/bar", true, + check_file_uri(NULL, "/foo/bar", "file:///foo/bar", NULL) || - check_file_uri("bhost", "/foo/bar", true, + check_file_uri("bhost", "/foo/bar", "file://bhost/foo/bar", NULL) || - check_file_uri(NULL, "a/relative path", false, - "a/relative path", NULL) || - check_file_uri(NULL, "a/relative ", true, + check_file_uri(NULL, "a/relative ", "a/relative%20%3Cpath%3E", NULL)) { return 1; } -- cgit v1.2.1