summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/object/uri.cpp7
-rw-r--r--testfiles/src/uri-test.cpp2
2 files changed, 8 insertions, 1 deletions
diff --git a/src/object/uri.cpp b/src/object/uri.cpp
index ce0953501..7c5ab657e 100644
--- a/src/object/uri.cpp
+++ b/src/object/uri.cpp
@@ -290,7 +290,12 @@ URI URI::from_dirname(gchar const *path)
pathstr = Glib::build_filename(Glib::get_current_dir(), pathstr);
}
- auto uristr = Glib::filename_to_uri(pathstr) + "/";
+ auto uristr = Glib::filename_to_uri(pathstr);
+
+ if (uristr[uristr.size() - 1] != '/') {
+ uristr.push_back('/');
+ }
+
return URI(uristr.c_str());
}
diff --git a/testfiles/src/uri-test.cpp b/testfiles/src/uri-test.cpp
index 3494386d9..6f0787af5 100644
--- a/testfiles/src/uri-test.cpp
+++ b/testfiles/src/uri-test.cpp
@@ -26,8 +26,10 @@ TEST(UriTest, FromDir)
{
#ifdef _WIN32
ASSERT_EQ(URI::from_dirname("C:\\tmp").str(), "file:///C:/tmp/");
+ ASSERT_EQ(URI::from_dirname("C:\\").str(), "file:///C:/");
ASSERT_EQ(URI::from_href_and_basedir("uri.svg", "C:\\tmp").str(), "file:///C:/tmp/uri.svg");
#else
+ ASSERT_EQ(URI::from_dirname("/").str(), "file:///");
ASSERT_EQ(URI::from_dirname("/tmp").str(), "file:///tmp/");
ASSERT_EQ(URI::from_href_and_basedir("uri.svg", "/tmp").str(), "file:///tmp/uri.svg");
#endif