1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-23 00:04:06 +00:00

TRAC-6098: Rework trailing slash stripping (once more)

Using QFileInfo to strip trailing slash(es) is bad when input contains non-
native paths (i.e. Windows paths on non-Windows system and vice versa) as it
may mistakenly treat the path as relative and change it in unespected way.
This commit is contained in:
Mike Gelfand 2016-10-03 22:22:25 +03:00
parent 7d22c1efc0
commit f6a19f868a

View file

@ -45,9 +45,9 @@
extern QPixmap qt_pixmapFromWinHICON(HICON icon);
#endif
#ifdef _WIN32
namespace
{
#ifdef _WIN32
void
addAssociatedFileIcon (const QFileInfo& fileInfo, UINT iconSize, QIcon& icon)
{
@ -83,9 +83,15 @@ namespace
if (!pixmap.isNull ())
icon.addPixmap (pixmap);
}
} // namespace
#endif
bool
isSlashChar (const QChar& c)
{
return c == QLatin1Char ('/') || c == QLatin1Char ('\\');
}
} // namespace
QIcon
Utils::guessMimeIcon (const QString& filename)
{
@ -201,8 +207,10 @@ Utils::isValidUtf8 (const char * s)
QString
Utils::removeTrailingDirSeparator (const QString& path)
{
const QFileInfo pathInfo (path);
return pathInfo.fileName ().isEmpty () ? pathInfo.absolutePath () : pathInfo.absoluteFilePath ();
int i = path.size ();
while (i > 1 && isSlashChar (path[i - 1]))
--i;
return path.left (i);
}
int