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:
parent
7d22c1efc0
commit
f6a19f868a
1 changed files with 12 additions and 4 deletions
16
qt/Utils.cc
16
qt/Utils.cc
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue