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