From 9033708633f085d7519489e84e5687326bc81432 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20=C5=81oskot?= Date: Thu, 3 Feb 2022 23:46:19 +0100 Subject: 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 --- src/filemanager.cpp | 37 +++++++++++++++++-------------------- 1 file changed, 17 insertions(+), 20 deletions(-) (limited to 'src') 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 { -- cgit v1.2.3