mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-09 18:31:04 +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 rTemp = tempRel;
|
||||||
string temp;
|
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()) {
|
while (!rTemp.empty()) {
|
||||||
// Split by next /
|
// Split by next /
|
||||||
rTemp = split(rTemp, temp, '/');
|
rTemp = split(rTemp, temp, '/');
|
||||||
@ -414,15 +423,22 @@ FileName const makeAbsPath(string const & relPath, string const & basePath)
|
|||||||
if (temp == ".") continue;
|
if (temp == ".") continue;
|
||||||
if (temp == "..") {
|
if (temp == "..") {
|
||||||
// Remove one level of TempBase
|
// Remove one level of TempBase
|
||||||
string::difference_type i = tempBase.length() - 2;
|
if (tempBase.length() <= 1) {
|
||||||
if (i < 0)
|
//this is supposed to be an absolute path, so...
|
||||||
i = 0;
|
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] != '/')
|
while (i > 0 && tempBase[i] != '/')
|
||||||
--i;
|
--i;
|
||||||
if (i > 0)
|
if (i > 0)
|
||||||
tempBase.erase(i, string::npos);
|
tempBase.erase(i, string::npos);
|
||||||
else
|
else
|
||||||
tempBase += '/';
|
tempBase = '/';
|
||||||
} else if (temp.empty() && !rTemp.empty()) {
|
} else if (temp.empty() && !rTemp.empty()) {
|
||||||
tempBase = os::current_root() + rTemp;
|
tempBase = os::current_root() + rTemp;
|
||||||
rTemp.erase();
|
rTemp.erase();
|
||||||
|
Loading…
Reference in New Issue
Block a user