From cc90f9cf803bc4aba928b2a80be451d9b717c5f0 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 4 Jun 2012 12:00:59 -0700 Subject: [PATCH] path_make_canonical mishandles empty string. Fixes https://github.com/ridiculousfish/fishfish/issues/26 --- fish_tests.cpp | 9 ++++++++- path.cpp | 4 ++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/fish_tests.cpp b/fish_tests.cpp index a6b4b2ab2..002912acd 100644 --- a/fish_tests.cpp +++ b/fish_tests.cpp @@ -576,7 +576,14 @@ static void test_path() if( canon != L"/foo/bar" ) { err( L"Bug in canonical PATH code" ); - } + } + + path = L"/"; + path_make_canonical(path); + if (path != L"/") + { + err( L"Bug in canonical PATH code" ); + } } /** Test is_potential_path */ diff --git a/path.cpp b/path.cpp index 3dcfcadd8..28f108389 100644 --- a/path.cpp +++ b/path.cpp @@ -525,8 +525,8 @@ void path_make_canonical( wcstring &path ) replace_all(path, L"//", L"/"); } while (path.size() != size); - /* Remove trailing slashes */ - while (size--) { + /* Remove trailing slashes, except don't remove the first one */ + while (size-- > 1) { if (path.at(size) != L'/') break; }