From 1a7b7f654151908e2123feb89d433480c26936a6 Mon Sep 17 00:00:00 2001 From: Richard Heck Date: Sat, 26 Jan 2008 20:41:19 +0000 Subject: [PATCH] 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 --- src/support/filetools.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp index f84891c349..e460efcf2f 100644 --- a/src/support/filetools.cpp +++ b/src/support/filetools.cpp @@ -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(); -- 2.39.2