diff --git a/common/env_paths.cpp b/common/env_paths.cpp index 97b658066a..0d431694f5 100644 --- a/common/env_paths.cpp +++ b/common/env_paths.cpp @@ -23,8 +23,8 @@ #include static bool normalizeAbsolutePaths( const wxFileName& aPathA, - const wxFileName& aPathB, - wxString* aResultPath ) + const wxFileName& aPathB, + wxString* aResultPath ) { wxCHECK_MSG( aPathA.IsAbsolute(), false, aPathA.GetPath() + " is not an absolute path." ); wxCHECK_MSG( aPathB.IsAbsolute(), false, aPathB.GetPath() + " is not an absolute path." ); @@ -56,7 +56,7 @@ static bool normalizeAbsolutePaths( const wxFileName& aPathA, { while( i < bDirs.GetCount() ) { - *aResultPath += bDirs[i] + wxT( "/" ); + *aResultPath += bDirs[i] + "/"; i++; } } @@ -70,6 +70,7 @@ wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars { wxFileName envPath; wxString tmp, varName, normalizedFullPath; + bool hasTrailingSeparator = false; if( aEnvVars ) { @@ -80,6 +81,12 @@ wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars || !wxFileName::IsDirReadable( entry.second.GetValue() ) ) continue; + // Do not add separator to the end of environment variable if it already has one. + wxUniChar separator = entry.second.GetValue().Last(); + + if( separator == '\\' || separator == '/' ) + hasTrailingSeparator = true; + envPath.SetPath( entry.second.GetValue() ); if( normalizeAbsolutePaths( envPath, aFilePath, &tmp ) ) @@ -100,7 +107,10 @@ wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars if( !varName.IsEmpty() ) { - normalizedFullPath = wxString::Format( "${%s}/", varName ); + normalizedFullPath = wxString::Format( "${%s}", varName ); + + if( !hasTrailingSeparator ) + normalizedFullPath += "/"; if( !tmp.IsEmpty() ) normalizedFullPath += tmp; diff --git a/include/env_paths.h b/include/env_paths.h index bac92ffcac..c9c55a74c0 100644 --- a/include/env_paths.h +++ b/include/env_paths.h @@ -28,10 +28,10 @@ #include /** - * Normalizes a file path to an environmental variable, if possible. + * Normalize a file path to an environmental variable, if possible. * * @param aFilePath is the full file path (path and file name) to be normalized. - * @param aEnvVars is an optional map of environmental variables to try substition with. + * @param aEnvVars is an optional map of environmental variables to try substitution with. * @param aProject is an optional project, to normalize the file path to the project path. * @return Normalized full file path (path and file name) if succeeded or empty string if the * path could not be normalized. @@ -40,13 +40,13 @@ wxString NormalizePath( const wxFileName& aFilePath, const ENV_VAR_MAP* aEnvVars const PROJECT* aProject ); /** - * Searches the default paths trying to find one with the requested file. + * Search the default paths trying to find one with the requested file. * * @param aFileName is the name of the searched file. It might be a relative path. * @param aEnvVars is an optional map of environmental variables that can contain paths. * @param aProject is an optional project, to check the project path. - * @return Full path (apth and file name) if the file was found in one of the paths, otherwise - * an empty string. + * @return Full path (path and file name) if the file was found in one of the paths, otherwise + * an empty string. */ wxString ResolveFile( const wxString& aFileName, const ENV_VAR_MAP* aEnvVars, const PROJECT* aProject );