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 5d5803d0..0d760f09 100644
--- a/include/serd/serd.h
+++ b/include/serd/serd.h
@@ -455,9 +455,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.
@@ -466,8 +465,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 7415ae36..cbb6762b 100644
--- a/src/node.c
+++ b/src/node.c
@@ -179,8 +179,7 @@ is_uri_path_char(const uint8_t c)
SerdNode
serd_node_new_file_uri(const uint8_t* path,
const uint8_t* hostname,
- SerdURI* out,
- bool escape)
+ SerdURI* out)
{
const size_t path_len = strlen((const char*)path);
const size_t hostname_len = hostname ? strlen((const char*)hostname) : 0;
@@ -209,7 +208,7 @@ serd_node_new_file_uri(const uint8_t* path,
serd_buffer_sink("/", 1, &buffer);
} else if (path[i] == '%') {
serd_buffer_sink("%%", 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, &buffer);
} else {
char escape_str[4] = {'%', 0, 0, 0};
diff --git a/src/serdi.c b/src/serdi.c
index a5c3c0da..0619c5fc 100644
--- a/src/serdi.c
+++ b/src/serdi.c
@@ -315,7 +315,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