From 4a96c934ba420f0caf6c32e7f04ced6eecb280ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=BCnter=20Obiltschnig?= Date: Thu, 29 Sep 2016 19:06:46 +0200 Subject: [PATCH] improvement of URIStreamOpener::open() implementation --- Foundation/src/Exception.cpp | 1 + Foundation/src/URIStreamOpener.cpp | 49 +++++++++++++++--------------- 2 files changed, 26 insertions(+), 24 deletions(-) diff --git a/Foundation/src/Exception.cpp b/Foundation/src/Exception.cpp index d2e9bc331..1dbdf0fa6 100644 --- a/Foundation/src/Exception.cpp +++ b/Foundation/src/Exception.cpp @@ -178,4 +178,5 @@ POCO_IMPLEMENT_EXCEPTION(URISyntaxException, SyntaxException, "Bad URI syntax") POCO_IMPLEMENT_EXCEPTION(ApplicationException, Exception, "Application exception") POCO_IMPLEMENT_EXCEPTION(BadCastException, RuntimeException, "Bad cast exception") + } // namespace Poco diff --git a/Foundation/src/URIStreamOpener.cpp b/Foundation/src/URIStreamOpener.cpp index 14ffa6d3a..b9494c4e2 100644 --- a/Foundation/src/URIStreamOpener.cpp +++ b/Foundation/src/URIStreamOpener.cpp @@ -65,22 +65,15 @@ std::istream* URIStreamOpener::open(const std::string& pathOrURI) const { return openURI(scheme, uri); } - else + else if (scheme.length() <= 1) // could be Windows path { Path path; if (path.tryParse(pathOrURI, Path::PATH_GUESS)) + { return openFile(path); - else - throw UnknownURISchemeException(pathOrURI); + } } - } - catch (UnknownURISchemeException&) - { - throw; - } - catch (TooManyURIRedirectsException&) - { - throw; + throw UnknownURISchemeException(pathOrURI); } catch (URISyntaxException&) { @@ -105,24 +98,32 @@ std::istream* URIStreamOpener::open(const std::string& basePathOrURI, const std: if (it != _map.end()) { uri.resolve(pathOrURI); + scheme = uri.getScheme(); return openURI(scheme, uri); } + else if (scheme.length() <= 1) // could be Windows path + { + Path base; + Path path; + if (base.tryParse(basePathOrURI, Path::PATH_GUESS) && path.tryParse(pathOrURI, Path::PATH_GUESS)) + { + base.resolve(path); + return openFile(base); + } + } + throw UnknownURISchemeException(basePathOrURI); } - catch (UnknownURISchemeException&) - { - throw; - } - catch (TooManyURIRedirectsException&) - { - throw; - } - catch (Exception&) + catch (URISyntaxException&) { + Path base; + Path path; + if (base.tryParse(basePathOrURI, Path::PATH_GUESS) && path.tryParse(pathOrURI, Path::PATH_GUESS)) + { + base.resolve(path); + return openFile(base); + } + else throw; } - Path base(basePathOrURI, Path::PATH_GUESS); - Path path(pathOrURI, Path::PATH_GUESS); - base.resolve(path); - return openFile(base); }