mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-12-22 05:16:21 +00:00
Fix some problems in makeAbsPath():
i. It didn't handle a leading "~" ii. It wrongly handled a string of ../../etc when this took us back to the root directory. Fix for (i) borrowed from expandPath(). The other is just logic. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@22687 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
6751c8a72f
commit
1a7b7f6541
@ -407,6 +407,15 @@ FileName const makeAbsPath(string const & relPath, string const & basePath)
|
||||
string rTemp = tempRel;
|
||||
string temp;
|
||||
|
||||
// Check for a leading "~"
|
||||
// Split by first /
|
||||
rTemp = split(rTemp, temp, '/');
|
||||
if (temp == "~") {
|
||||
tempBase = package().home_dir().absFilename();
|
||||
tempRel = rTemp;
|
||||
}
|
||||
|
||||
rTemp = tempRel;
|
||||
while (!rTemp.empty()) {
|
||||
// Split by next /
|
||||
rTemp = split(rTemp, temp, '/');
|
||||
@ -414,15 +423,22 @@ FileName const makeAbsPath(string const & relPath, string const & basePath)
|
||||
if (temp == ".") continue;
|
||||
if (temp == "..") {
|
||||
// Remove one level of TempBase
|
||||
string::difference_type i = tempBase.length() - 2;
|
||||
if (i < 0)
|
||||
i = 0;
|
||||
if (tempBase.length() <= 1) {
|
||||
//this is supposed to be an absolute path, so...
|
||||
tempBase = "/";
|
||||
continue;
|
||||
}
|
||||
//erase a trailing slash if there is one
|
||||
if (suffixIs(tempBase, "/"))
|
||||
tempBase.erase(tempBase.length() - 1, string::npos);
|
||||
|
||||
string::size_type i = tempBase.length() - 1;
|
||||
while (i > 0 && tempBase[i] != '/')
|
||||
--i;
|
||||
if (i > 0)
|
||||
tempBase.erase(i, string::npos);
|
||||
else
|
||||
tempBase += '/';
|
||||
tempBase = '/';
|
||||
} else if (temp.empty() && !rTemp.empty()) {
|
||||
tempBase = os::current_root() + rTemp;
|
||||
rTemp.erase();
|
||||
|
Loading…
Reference in New Issue
Block a user