aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--include/serd/serd.h8
-rw-r--r--src/node.c5
-rw-r--r--src/serdi.c2
-rw-r--r--test/test_uri.c15
4 files changed, 11 insertions, 19 deletions
diff --git a/include/serd/serd.h b/include/serd/serd.h
index 773574f0..0d9a4444 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -405,9 +405,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.
@@ -416,8 +415,7 @@ 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.
diff --git a/src/node.c b/src/node.c
index c444546d..34de3bfb 100644
--- a/src/node.c
+++ b/src/node.c
@@ -181,8 +181,7 @@ is_uri_path_char(const uint8_t 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;
@@ -211,7 +210,7 @@ serd_node_new_file_uri(const uint8_t* const path,
serd_chunk_sink("/", 1, &chunk);
} else 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);
} else {
char escape_str[4] = {'%', 0, 0, 0};
diff --git a/src/serdi.c b/src/serdi.c
index 06d83816..c594a30a 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -322,7 +322,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 e0348049..554b4a93 100644
--- a/test/test_uri.c
+++ b/test/test_uri.c
@@ -19,7 +19,6 @@
#include "serd/serd.h"
#include <assert.h>
-#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
@@ -29,7 +28,6 @@
static void
test_file_uri(const char* hostname,
const char* path,
- bool escape,
const char* expected_uri,
const char* expected_path)
{
@@ -37,7 +35,7 @@ test_file_uri(const char* 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);
@@ -53,17 +51,14 @@ test_file_uri(const char* hostname,
static void
test_uri_parsing(void)
{
- test_file_uri(NULL, "C:/My 100%", true, "file:///C:/My%20100%%", NULL);
+ test_file_uri(NULL, "C:/My 100%", "file:///C:/My%20100%%", NULL);
test_file_uri("ahost",
"C:\\Pointless Space",
- true,
"file://ahost/C:/Pointless%20Space",
"C:/Pointless Space");
- 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, "/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);
// Test tolerance of parsing junk URI escapes