diff options
-rw-r--r-- | include/serd/serd.h | 8 | ||||
-rw-r--r-- | src/node.c | 5 | ||||
-rw-r--r-- | src/serdi.c | 2 | ||||
-rw-r--r-- | test/test_uri.c | 35 |
4 files changed, 16 insertions, 34 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h index 851dce1b..69315b18 100644 --- a/include/serd/serd.h +++ b/include/serd/serd.h @@ -379,9 +379,8 @@ serd_node_new_uri_from_string(const uint8_t* SERD_NULLABLE str, /** 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. @@ -389,8 +388,7 @@ serd_node_new_uri_from_string(const uint8_t* SERD_NULLABLE str, SERD_API SerdNode serd_node_new_file_uri(const uint8_t* SERD_NONNULL path, const uint8_t* SERD_NULLABLE hostname, - SerdURI* SERD_NULLABLE out, - bool escape); + SerdURI* SERD_NULLABLE out); /** Create a new node by serialising `uri` into a new string. @@ -178,8 +178,7 @@ is_dir_sep(const char c) SerdNode serd_node_new_file_uri(const uint8_t* const path, const uint8_t* const hostname, - SerdURI* const out, - const bool escape) + SerdURI* const out) { const size_t path_len = strlen((const char*)path); const size_t hostname_len = hostname ? strlen((const char*)hostname) : 0; @@ -206,7 +205,7 @@ serd_node_new_file_uri(const uint8_t* const path, for (size_t i = 0; i < path_len; ++i) { if (path[i] == '%') { serd_chunk_sink("%%", 2, &chunk); - } else if (!escape || is_uri_path_char(path[i])) { + } else if (is_uri_path_char(path[i])) { serd_chunk_sink(path + i, 1, &chunk); #ifdef _WIN32 } else if (path[i] == '\\') { diff --git a/src/serdi.c b/src/serdi.c index 2bea9e3a..6ab55b20 100644 --- a/src/serdi.c +++ b/src/serdi.c @@ -323,7 +323,7 @@ main(int argc, char** argv) base = serd_node_new_uri_from_string((const uint8_t*)argv[a], NULL, &base_uri); } else if (from_file && in_fd != stdin) { // Use input file URI - base = serd_node_new_file_uri(input, NULL, &base_uri, true); + base = serd_node_new_file_uri(input, NULL, &base_uri); } FILE* const out_fd = stdout; diff --git a/test/test_uri.c b/test/test_uri.c index daa64240..2747d008 100644 --- a/test/test_uri.c +++ b/test/test_uri.c @@ -37,7 +37,6 @@ test_uri_string_has_scheme(void) static void test_file_uri(const char* const hostname, const char* const path, - const bool escape, const char* const expected_uri, const char* expected_path) { @@ -45,7 +44,7 @@ test_file_uri(const char* const hostname, expected_path = path; } - SerdNode node = serd_node_new_file_uri(USTR(path), USTR(hostname), 0, escape); + SerdNode node = serd_node_new_file_uri(USTR(path), USTR(hostname), 0); uint8_t* out_hostname = NULL; uint8_t* out_path = serd_file_uri_parse(node.buf, &out_hostname); @@ -62,32 +61,24 @@ test_file_uri(const char* const hostname, static void test_uri_parsing(void) { - test_file_uri(NULL, "C:/My 100%", true, "file:///C:/My%20100%%", NULL); - test_file_uri(NULL, "/foo/bar", true, "file:///foo/bar", NULL); - test_file_uri("bhost", "/foo/bar", true, "file://bhost/foo/bar", NULL); - test_file_uri(NULL, "a/relative path", false, "a/relative path", NULL); - test_file_uri( - NULL, "a/relative <path>", true, "a/relative%20%3Cpath%3E", NULL); + test_file_uri(NULL, "C:/My 100%", "file:///C:/My%20100%%", NULL); + test_file_uri(NULL, "/foo/bar", "file:///foo/bar", NULL); + test_file_uri("bhost", "/foo/bar", "file://bhost/foo/bar", NULL); + test_file_uri(NULL, "a/relative <path>", "a/relative%20%3Cpath%3E", NULL); #ifdef _WIN32 - test_file_uri( - NULL, "C:\\My 100%", true, "file:///C:/My%20100%%", "C:/My 100%"); + test_file_uri(NULL, "C:\\My 100%", "file:///C:/My%20100%%", "C:/My 100%"); - test_file_uri(NULL, - "\\drive\\relative", - true, - "file:///drive/relative", - "/drive/relative"); + test_file_uri( + NULL, "\\drive\\relative", "file:///drive/relative", "/drive/relative"); test_file_uri(NULL, "C:\\Program Files\\Serd", - true, "file:///C:/Program%20Files/Serd", "C:/Program Files/Serd"); test_file_uri("ahost", "C:\\Pointless Space", - true, "file://ahost/C:/Pointless%20Space", "C:/Pointless Space"); #else @@ -97,25 +88,19 @@ test_uri_parsing(void) test_file_uri("ahost", "C:\\Pointless Space", - true, "file://ahost/C:%5CPointless%20Space", "/C:\\Pointless Space"); - test_file_uri(NULL, - "\\drive\\relative", - true, - "%5Cdrive%5Crelative", - "\\drive\\relative"); + test_file_uri( + NULL, "\\drive\\relative", "%5Cdrive%5Crelative", "\\drive\\relative"); test_file_uri(NULL, "C:\\Program Files\\Serd", - true, "file:///C:%5CProgram%20Files%5CSerd", "/C:\\Program Files\\Serd"); test_file_uri("ahost", "C:\\Pointless Space", - true, "file://ahost/C:%5CPointless%20Space", "/C:\\Pointless Space"); #endif |