aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateusz Łoskot <mateusz@loskot.net>2022-02-03 23:46:19 +0100
committerGitHub <noreply@github.com>2022-02-03 23:46:19 +0100
commit9033708633f085d7519489e84e5687326bc81432 (patch)
tree98e4b31463af1e439a40ba952e4ab06b972276b2
parentfc46c5bac52a20d56ea09566accfcb91198116a0 (diff)
downloadPROJ-9033708633f085d7519489e84e5687326bc81432.tar.gz
PROJ-9033708633f085d7519489e84e5687326bc81432.zip
Allow PROJ_LIB paths wrapped with double quotes (#3031)
This improvement is mostly useful on Windows, where users are used to wrapping paths with whitespaces with double quotes. For example, these should now be allowed (correctly concatenated): PROJ_LIB="C:\Program Files\PROJ";C:\Users\mloskot\PROJ
-rw-r--r--src/filemanager.cpp37
1 files changed, 17 insertions, 20 deletions
diff --git a/src/filemanager.cpp b/src/filemanager.cpp
index 8ab8e6c4..02845a8f 100644
--- a/src/filemanager.cpp
+++ b/src/filemanager.cpp
@@ -1420,6 +1420,21 @@ static void *pj_open_lib_internal(
if (out_full_filename != nullptr && out_full_filename_size > 0)
out_full_filename[0] = '\0';
+ auto open_lib_from_paths = [&ctx, open_file, &name, &fname, &sysname, &mode](const std::string & projLibPaths) {
+ void *lib_fid = nullptr;
+ auto paths = NS_PROJ::internal::split(projLibPaths, dirSeparator);
+ for (const auto& path : paths) {
+ fname = NS_PROJ::internal::stripQuotes(path);
+ fname += DIR_CHAR;
+ fname += name;
+ sysname = fname.c_str();
+ lib_fid = open_file(ctx, sysname, mode);
+ if (lib_fid)
+ break;
+ }
+ return lib_fid;
+ };
+
/* check if ~/name */
if (is_tilde_slash(name))
if ((sysname = getenv("HOME")) != nullptr) {
@@ -1487,16 +1502,7 @@ static void *pj_open_lib_internal(
else if (!gbPROJ_LIB_ENV_VAR_TRIED_LAST &&
!(projLib = NS_PROJ::FileManager::getProjLibEnvVar(ctx))
.empty()) {
- auto paths = NS_PROJ::internal::split(projLib, dirSeparator);
- for (const auto &path : paths) {
- fname = path;
- fname += DIR_CHAR;
- fname += name;
- sysname = fname.c_str();
- fid = open_file(ctx, sysname, mode);
- if (fid)
- break;
- }
+ fid = open_lib_from_paths(projLib);
}
else if ((sysname = get_path_from_relative_share_proj(
@@ -1519,16 +1525,7 @@ static void *pj_open_lib_internal(
else if (gbPROJ_LIB_ENV_VAR_TRIED_LAST &&
!(projLib = NS_PROJ::FileManager::getProjLibEnvVar(ctx))
.empty()) {
- auto paths = NS_PROJ::internal::split(projLib, dirSeparator);
- for (const auto &path : paths) {
- fname = path;
- fname += DIR_CHAR;
- fname += name;
- sysname = fname.c_str();
- fid = open_file(ctx, sysname, mode);
- if (fid)
- break;
- }
+ fid = open_lib_from_paths(projLib);
}
else {