From: Enrico Forestieri Date: Mon, 25 May 2009 00:23:44 +0000 (+0000) Subject: Account for the corner case p2.length() == 1. X-Git-Tag: 2.0.0~6453 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=eb9151060dbed8383946e9da782a75cb3794fda1;p=features.git Account for the corner case p2.length() == 1. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@29838 a592a061-630c-0410-9148-cb99ea01b6c8 --- diff --git a/src/support/os_cygwin.cpp b/src/support/os_cygwin.cpp index 43e56bbfd3..f33e7af4d6 100644 --- a/src/support/os_cygwin.cpp +++ b/src/support/os_cygwin.cpp @@ -179,13 +179,19 @@ bool path_prefix_is(string & path, string const & pre, path_case how) { docstring const p1 = from_utf8(path); docstring const p2 = from_utf8(pre); - docstring::size_type i = common_path(p1, p2); + docstring::size_type const p1_len = p1.length(); + docstring::size_type const p2_len = p2.length(); + docstring::size_type const common_len = common_path(p1, p2) + 1; - if (i == 0 || i + 1 != p2.length()) + if (common_len == 1) { + if (p2_len != 1 || p1_len == 0 || p1[0] != p2[0] + || (p1_len != 1 && p1[1] != '/')) + return false; + } else if (common_len != p2_len) return false; if (how == CASE_ADJUSTED && !prefixIs(path, pre)) - path = to_utf8(p2 + p1.substr(i + 1, p1.length() - i + 1)); + path = to_utf8(p2 + p1.substr(common_len, p1_len - common_len)); return true; } diff --git a/src/support/os_unix.cpp b/src/support/os_unix.cpp index 2463111abc..b7a5b10daa 100644 --- a/src/support/os_unix.cpp +++ b/src/support/os_unix.cpp @@ -92,13 +92,19 @@ bool path_prefix_is(string & path, string const & pre, path_case how) #ifdef __APPLE__ docstring const p1 = from_utf8(path); docstring const p2 = from_utf8(pre); - docstring::size_type i = common_path(p1, p2); + docstring::size_type const p1_len = p1.length(); + docstring::size_type const p2_len = p2.length(); + docstring::size_type const common_len = common_path(p1, p2) + 1; - if (i == 0 || i + 1 != p2.length()) + if (common_len == 1) { + if (p2_len != 1 || p1_len == 0 || p1[0] != p2[0] + || (p1_len != 1 && p1[1] != '/')) + return false; + } else if (common_len != p2_len) return false; if (how == CASE_ADJUSTED && !prefixIs(path, pre)) - path = to_utf8(p2 + p1.substr(i + 1, p1.length() - i + 1)); + path = to_utf8(p2 + p1.substr(common_len, p1_len - common_len)); return true; #else diff --git a/src/support/os_win32.cpp b/src/support/os_win32.cpp index 65503f1672..c51b37745d 100644 --- a/src/support/os_win32.cpp +++ b/src/support/os_win32.cpp @@ -210,13 +210,19 @@ bool path_prefix_is(string & path, string const & pre, path_case how) { docstring const p1 = from_utf8(path); docstring const p2 = from_utf8(pre); - docstring::size_type i = common_path(p1, p2); + docstring::size_type const p1_len = p1.length(); + docstring::size_type const p2_len = p2.length(); + docstring::size_type const common_len = common_path(p1, p2) + 1; - if (i == 0 || i + 1 != p2.length()) + if (common_len == 1) { + if (p2_len != 1 || p1_len == 0 || p1[0] != p2[0] + || (p1_len != 1 && p1[1] != '/')) + return false; + } else if (common_len != p2_len) return false; if (how == CASE_ADJUSTED && !prefixIs(path, pre)) - path = to_utf8(p2 + p1.substr(i + 1, p1.length() - i + 1)); + path = to_utf8(p2 + p1.substr(common_len, p1_len - common_len)); return true; }