// !! Fall through !!
case wxPATH_UNIX:
- // the paths of the form "~" or "~username" are absolute
- m_relative = leadingChar != wxT('/') && leadingChar != _T('~');
+ m_relative = leadingChar != wxT('/');
break;
case wxPATH_DOS:
}
// handle ~ stuff under Unix only
- if ( (format == wxPATH_UNIX) && (flags & wxPATH_NORM_TILDE) )
+ if ( (format == wxPATH_UNIX) && (flags & wxPATH_NORM_TILDE) && m_relative )
{
if ( !dirs.IsEmpty() )
{
{
// to make the path absolute use the home directory
curDir.AssignDir(wxGetUserHome(dir.c_str() + 1));
-
- // if we are expanding the tilde, then this path
- // *should* be already relative (since we checked for
- // the tilde only in the first char of the first dir);
- // if m_relative==false, it's because it was initialized
- // from a string which started with /~; in that case
- // we reach this point but then need m_relative=true
- // for relative->absolute expansion later
- m_relative = true;
-
dirs.RemoveAt(0u);
}
}
// if we used e.g. tilde expansion previously and wxGetUserHome didn't
// return for some reason an absolute path, then curDir maybe not be absolute!
- if ( curDir.IsAbsolute(format) )
+ if ( !curDir.m_relative )
{
// we have prepended an absolute path and thus we are now an absolute
// file name too
bool wxFileName::IsAbsolute(wxPathFormat format) const
{
+ // unix paths beginning with ~ are reported as being absolute
+ if ( format == wxPATH_UNIX )
+ {
+ if ( !m_dirs.IsEmpty() )
+ {
+ wxString dir = m_dirs[0u];
+
+ if (!dir.empty() && dir[0u] == _T('~'))
+ return true;
+ }
+ }
+
// if our path doesn't start with a path separator, it's not an absolute
// path
if ( m_relative )
if ( !GetVolumeSeparator(format).empty() )
{
// this format has volumes and an absolute path must have one, it's not
- // enough to have the full path to bean absolute file under Windows
+ // enough to have the full path to be an absolute file under Windows
if ( GetVolume().empty() )
return false;
}
case wxPATH_UNIX:
if ( !m_relative )
{
- // normally the absolute file names start with a slash
- // with one exception: the ones like "~/foo.bar" don't
- // have it
- if ( m_dirs.IsEmpty() || m_dirs[0u] != _T('~') )
- {
- fullpath += wxFILE_SEP_PATH_UNIX;
- }
+ fullpath += wxFILE_SEP_PATH_UNIX;
}
break;
{ "../../foo", "", "../..", "foo", "", false, wxPATH_UNIX },
{ "foo.bar", "", "", "foo", "bar", false, wxPATH_UNIX },
{ "~/foo.bar", "", "~", "foo", "bar", true, wxPATH_UNIX },
+ { "~user/foo.bar", "", "~user", "foo", "bar", true, wxPATH_UNIX },
+ { "~user/", "", "~user", "", "", true, wxPATH_UNIX },
{ "/foo", "", "/", "foo", "", true, wxPATH_UNIX },
{ "Mahogany-0.60/foo.bar", "", "Mahogany-0.60", "foo", "bar", false, wxPATH_UNIX },
{ "/tmp/wxwin.tar.bz", "", "/tmp", "wxwin.tar", "bz", true, wxPATH_UNIX },
// test wxPATH_NORM_DOTS
{ "a/.././b/c/../../", wxPATH_NORM_DOTS, "", wxPATH_UNIX },
- // test wxPATH_NORM_TILDE
- // NB: do the tilde expansion also under Windows to test if it works there too
+ // test wxPATH_NORM_TILDE: notice that ~ is only interpreted specially
+ // when it is the first character in the file name
{ "/a/b/~", wxPATH_NORM_TILDE, "/a/b/~", wxPATH_UNIX },
- { "/~/a/b", wxPATH_NORM_TILDE, "HOME/a/b", wxPATH_UNIX },
+ { "/~/a/b", wxPATH_NORM_TILDE, "/~/a/b", wxPATH_UNIX },
{ "~/a/b", wxPATH_NORM_TILDE, "HOME/a/b", wxPATH_UNIX },
// test wxPATH_NORM_CASE