Don't allow !addincludedir with trailing path separator to propagate to !include

git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@6526 212acab6-be3b-0410-9dea-997c60f758d6
This commit is contained in:
anders_k 2014-07-18 16:37:08 +00:00
parent d66c9a492f
commit ad03365921
3 changed files with 30 additions and 17 deletions

View file

@ -1366,14 +1366,9 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
SCRIPT_MSG(_T("!delfile: \"%") NPRIs _T("\"\n"), line.gettoken_str(a));
tstring dir = get_dir_name(fc);
tstring spec = get_file_name(fc);
tstring dir = get_dir_name(fc), spec = get_file_name(fc);
tstring basedir = dir + PLATFORM_PATH_SEPARATOR_STR;
if (dir == spec) {
// no path, just file name
dir = _T(".");
basedir = _T("");
}
if (dir == spec) dir = _T("."), basedir = _T(""); // no path, just file name
boost::scoped_ptr<dir_reader> dr( new_dir_reader() );
dr->read(dir); // BUGBUG: PATH_CONVERT?
@ -3200,12 +3195,10 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
{
f = line.gettoken_str(++tok);
if (tok >= toks) break;
if(!_tcsicmp(f,_T("/nonfatal"))) {
required = false;
}
if (!_tcsicmp(f,_T("/nonfatal"))) required = false;
TCHAR buf[9+1];
my_strncpy(buf,f,COUNTOF(buf));
if(!_tcsicmp(buf,_T("/charset="))) {
if (!_tcsicmp(buf,_T("/charset="))) {
WORD cp = GetEncodingFromString(f+9);
if (NStreamEncoding::UNKNOWN == cp) toks = 0;
enc.SafeSetCodepage(cp);
@ -3214,9 +3207,8 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
if (!toks || !*f) PRINTHELP();
TCHAR *fc = my_convert(f);
tstring dir = get_dir_name(fc);
tstring spec = get_file_name(fc);
tstring basedir = dir + PLATFORM_PATH_SEPARATOR_STR;
tstring dir = get_dir_name(fc), spec = get_file_name(fc), basedir = dir;
path_append_separator(basedir);
if (dir == spec) basedir = _T(""), dir = _T("."); // no path, just file name
my_convert_free(fc);
@ -3228,7 +3220,6 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
files_itr++)
{
if (!dir_reader::matches(*files_itr, spec)) continue;
tstring incfile = basedir + *files_itr;
if (includeScript(incfile.c_str(), enc) != PS_OK)
return PS_ERROR;
@ -3241,7 +3232,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
TCHAR *incdir = include_dirs.get();
int incdirs = include_dirs.getnum();
for (int i = 0; i < incdirs; i++, incdir += _tcslen(incdir) + 1) {
tstring curincdir = tstring(incdir) + PLATFORM_PATH_SEPARATOR_STR + dir;
tstring curincdir = path_append(tstring(incdir), dir);
boost::scoped_ptr<dir_reader> dr( new_dir_reader() );
dr->read(curincdir);
@ -3251,7 +3242,7 @@ int CEXEBuild::doCommand(int which_token, LineParser &line)
{
if (!dir_reader::matches(*incdir_itr, spec)) continue;
tstring incfile = tstring(incdir) + PLATFORM_PATH_SEPARATOR_STR + basedir + *incdir_itr;
tstring incfile = path_append(tstring(incdir), basedir) + *incdir_itr;
if (includeScript(incfile.c_str(), enc) != PS_OK)
return PS_ERROR;
else

View file

@ -718,6 +718,20 @@ tstring remove_file_extension(const tstring& path) {
return get_string_prefix(path, _T("."));
}
tstring& path_append_separator(tstring& path)
{
tstring::iterator ib = path.begin(), ie = path.end();
if (ib != ie && !IsPathSeparator(*--ie))
path.push_back(PLATFORM_PATH_SEPARATOR_C);
return path;
}
tstring& path_append(tstring& base, const TCHAR* more)
{
if (IsPathSeparator(*more)) ++more;
return path_append_separator(base) += more;
}
static int PathGetDosDriveNumber(const TCHAR *p)
{
// Note: Unlike PathGetDriveNumber(), we require a path separator after the colon.

View file

@ -48,6 +48,14 @@ tstring get_file_name(const tstring& path);
tstring get_executable_path(const TCHAR* argv0);
tstring get_executable_dir(const TCHAR *argv0);
tstring remove_file_extension(const tstring& path);
tstring& path_append_separator(tstring& path);
tstring& path_append(tstring& base, const TCHAR* more);
inline tstring& path_append(tstring& base, const tstring& more) { return path_append(base, more.c_str()); }
#ifdef _WIN32
#define IsPathSeparator IsAgnosticPathSeparator
#else
#define IsPathSeparator(c) ( PLATFORM_PATH_SEPARATOR_C == (c) )
#endif
inline bool IsAgnosticPathSeparator(const TCHAR c) { return _T('\\') == c || _T('/') == c; }
bool IsWindowsPathRelative(const TCHAR *p);