From d8a4d16f720acdf77b6af446d473574bdbec796f Mon Sep 17 00:00:00 2001
From: Bill Hoffman <bill.hoffman@kitware.com>
Date: Thu, 6 May 2004 10:29:29 -0400
Subject: [PATCH] BUG: fix collapse full path to handle a file in the root
 directory

---
 SystemTools.cxx | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/SystemTools.cxx b/SystemTools.cxx
index 755fe289..8e703cd3 100644
--- a/SystemTools.cxx
+++ b/SystemTools.cxx
@@ -725,7 +725,7 @@ void SystemTools::ConvertToUnixSlashes(kwsys_stl::string& path)
     }
   
   // remove any trailing slash
-  if(path.size() && path[path.size()-1] == '/')
+  if(path.size() > 1 && path[path.size()-1] == '/')
     {
     path = path.substr(0, path.size()-1);
     }
@@ -1364,6 +1364,12 @@ kwsys_stl::string SystemTools::CollapseFullPath(const char* in_relative,
   
   kwsys_stl::string dir, file;
   SystemTools::SplitProgramPath(in_relative, dir, file, false);
+  if(dir.size() == 0 && 
+      in_relative && strlen(in_relative) > 0 &&
+      in_relative[0] == '/')
+     {
+     dir = "/";
+     }
   
 #ifdef _WIN32
   // Follow relative path.
@@ -1413,7 +1419,10 @@ kwsys_stl::string SystemTools::CollapseFullPath(const char* in_relative,
   kwsys_stl::string newPath = newDir;
   if(!(file == ""))
     {
-    newPath += "/";
+    if(!(newDir.size() == 1 && newDir[0] ==  '/'))
+      {
+      newPath += "/";
+      }
     newPath += file;
     }
   return newPath;
-- 
GitLab