From: Michael Andres Date: Thu, 17 Jul 2014 12:53:03 +0000 (+0200) Subject: fix wrong '//' when extending URLs with an empty path (bnc#885254) X-Git-Tag: upstream/14.27.0~9 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8f5d2f29addc246e80829e4cf51cea3fd570b0ff;p=platform%2Fupstream%2Flibzypp.git fix wrong '//' when extending URLs with an empty path (bnc#885254) 1st '/' is just a separator: ftp://user@server -> ~user ftp://user@server/ -> ~user ftp://user@server// -> / --- diff --git a/zypp/media/MediaCurl.cc b/zypp/media/MediaCurl.cc index 7c50687..444bfc7 100644 --- a/zypp/media/MediaCurl.cc +++ b/zypp/media/MediaCurl.cc @@ -836,31 +836,29 @@ void MediaCurl::releaseFrom( const std::string & ejectDev ) disconnect(); } -Url MediaCurl::getFileUrl(const Pathname & filename) const +Url MediaCurl::getFileUrl( const Pathname & filename_r ) const { - Url newurl(_url); - string path = _url.getPathName(); - if ( !path.empty() && path != "/" && *path.rbegin() == '/' && - filename.absolute() ) + std::string path( _url.getPathName() ); + // Simply extend the URLs pathname. An 'absolute' URL path + // is achieved by encoding the 2nd '/' in the URL: + // URL: ftp://user@server -> ~user + // URL: ftp://user@server/ -> ~user + // URL: ftp://user@server// -> / + // ^- this '/' is just a separator + if ( path.empty() || path == "/" ) // empty URL path; the '/' is just a separator { - // If url has a path with trailing slash, remove the leading slash from - // the absolute file name - path += filename.asString().substr( 1, filename.asString().size() - 1 ); + path = filename_r.absolutename().asString(); } - else if ( filename.relative() ) + else if ( *path.rbegin() == '/' ) { - // Add trailing slash to path, if not already there - if (path.empty()) path = "/"; - else if (*path.rbegin() != '/' ) path += "/"; - // Remove "./" from begin of relative file name - path += filename.asString().substr( 2, filename.asString().size() - 2 ); + path += filename_r.absolutename().asString().substr(1); } else { - path += filename.asString(); + path += filename_r.absolutename().asString(); } - - newurl.setPathName(path); + Url newurl( _url ); + newurl.setPathName( path ); return newurl; }