diff --git a/src/cosim/orchestration.cpp b/src/cosim/orchestration.cpp index dea4bfff..c5afea9f 100644 --- a/src/cosim/orchestration.cpp +++ b/src/cosim/orchestration.cpp @@ -118,10 +118,12 @@ std::shared_ptr fmu_file_uri_sub_resolver::lookup_model(const uri& modelU { assert(modelUri.scheme().has_value()); if (*modelUri.scheme() != "file") return nullptr; +#ifndef _WIN32 if (modelUri.authority().has_value() && !(modelUri.authority()->empty() || *modelUri.authority() == "localhost")) { return nullptr; } +#endif if (modelUri.query().has_value() || modelUri.fragment().has_value()) { BOOST_LOG_SEV(log::logger(), log::warning) << "Query and/or fragment component(s) in a file:// URI were ignored: " diff --git a/src/cosim/uri.cpp b/src/cosim/uri.cpp index db5857a0..a2889d8b 100644 --- a/src/cosim/uri.cpp +++ b/src/cosim/uri.cpp @@ -529,9 +529,6 @@ uri path_to_file_uri(const cosim::filesystem::path& path) cosim::filesystem::path file_uri_to_path(const uri& fileUri) { COSIM_INPUT_CHECK(fileUri.scheme() && *fileUri.scheme() == "file"); - COSIM_INPUT_CHECK(fileUri.authority() && - (fileUri.authority()->empty() || *fileUri.authority() == "localhost")); - #ifdef _WIN32 // Windows has some special rules for file URIs; better use the built-in // functions. @@ -554,6 +551,8 @@ cosim::filesystem::path file_uri_to_path(const uri& fileUri) return cosim::filesystem::path(pathBuffer, pathBuffer + pathSize); #else + COSIM_INPUT_CHECK(fileUri.authority() && + (fileUri.authority()->empty() || *fileUri.authority() == "localhost")); return cosim::filesystem::path(percent_decode(fileUri.path())); #endif } diff --git a/tests/uri_unittest.cpp b/tests/uri_unittest.cpp index e5e74529..2abf4582 100644 --- a/tests/uri_unittest.cpp +++ b/tests/uri_unittest.cpp @@ -205,6 +205,7 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) BOOST_TEST(path_to_file_uri("\\foo bar\\baz") == "file:///foo%20bar/baz"); BOOST_TEST(path_to_file_uri("/foo bar/baz") == "file:///foo%20bar/baz"); BOOST_TEST(path_to_file_uri("c:\\foo bar\\baz") == "file:///c:/foo%20bar/baz"); + BOOST_TEST(path_to_file_uri("\\\\foo\\bar\\baz") == "file://foo/bar/baz"); #endif // From URI to path @@ -213,12 +214,13 @@ BOOST_AUTO_TEST_CASE(file_uri_conversions) BOOST_TEST(file_uri_to_path("file:///c:/foo%20bar/baz") == "c:\\foo bar\\baz"); BOOST_TEST(file_uri_to_path("file://localhost/foo%20bar/baz") == "\\foo bar\\baz"); BOOST_TEST(file_uri_to_path("file://localhost/c:/foo%20bar/baz") == "c:\\foo bar\\baz"); + BOOST_TEST(file_uri_to_path("file://foo/bar/baz") == "\\\\foo\\bar\\baz"); #else BOOST_TEST(file_uri_to_path("file:///foo%20bar/baz") == "/foo bar/baz"); BOOST_TEST(file_uri_to_path("file:///c:/foo%20bar/baz") == "/c:/foo bar/baz"); BOOST_TEST(file_uri_to_path("file://localhost/foo%20bar/baz") == "/foo bar/baz"); BOOST_TEST(file_uri_to_path("file://localhost/c:/foo%20bar/baz") == "/c:/foo bar/baz"); + BOOST_CHECK_THROW(file_uri_to_path("file://foo/bar"), std::invalid_argument); #endif BOOST_CHECK_THROW(file_uri_to_path("http://foo/bar"), std::invalid_argument); - BOOST_CHECK_THROW(file_uri_to_path("file://foo/bar"), std::invalid_argument); }