diff options
author | Konstantin Käfer <mail@kkaefer.com> | 2018-01-24 08:34:05 -0800 |
---|---|---|
committer | Konstantin Käfer <mail@kkaefer.com> | 2018-01-24 16:28:31 -0800 |
commit | a469c93ae575ecc32a5f76a8a7add9a9883ce051 (patch) | |
tree | 8b997654bbd09a1fc91beeb919df9f3fc85ca9bc /platform/default/asset_file_source.cpp | |
parent | 2502a3ab2bf793dcb3a41deb5c93290b3c6ce5fd (diff) | |
download | qtlocation-mapboxgl-upstream/local-asset-filesource.tar.gz |
[core] align implementations of local and asset file sourceupstream/local-asset-filesource
Diffstat (limited to 'platform/default/asset_file_source.cpp')
-rw-r--r-- | platform/default/asset_file_source.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/platform/default/asset_file_source.cpp b/platform/default/asset_file_source.cpp index 54dbb8d0f6..3063bf88a0 100644 --- a/platform/default/asset_file_source.cpp +++ b/platform/default/asset_file_source.cpp @@ -10,6 +10,12 @@ #include <sys/types.h> #include <sys/stat.h> +namespace { + +const std::string assetProtocol = "asset://"; + +} // namespace + namespace mbgl { class AssetFileSource::Impl { @@ -19,18 +25,17 @@ public: } void request(const std::string& url, ActorRef<FileSourceRequest> req) { - std::string path; + Response response; - if (url.size() <= 8 || url[8] == '/') { - // This is an empty or absolute path. - path = mbgl::util::percentDecode(url.substr(8)); - } else { - // This is a relative path. Prefix with the application root. - path = root + "/" + mbgl::util::percentDecode(url.substr(8)); + if (!acceptsURL(url)) { + response.error = std::make_unique<Response::Error>(Response::Error::Reason::Other, + "Invalid asset URL"); + req.invoke(&FileSourceRequest::setResponse, response); + return; } - Response response; - + // Cut off the protocol and prefix with path. + const auto path = root + "/" + mbgl::util::percentDecode(url.substr(assetProtocol.size())); struct stat buf; int result = stat(path.c_str(), &buf); @@ -69,4 +74,8 @@ std::unique_ptr<AsyncRequest> AssetFileSource::request(const Resource& resource, return std::move(req); } +bool AssetFileSource::acceptsURL(const std::string& url) { + return std::equal(assetProtocol.begin(), assetProtocol.end(), url.begin()); +} + } // namespace mbgl |