Utils: Avoid adding duplicated slashs in FilePath::pathAppended

Change-Id: I791412906e94a967a61d9b3212b704936c447183
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2021-08-13 11:39:54 +02:00
parent 3611fb1065
commit 142a34464f
2 changed files with 71 additions and 3 deletions

View File

@@ -1198,9 +1198,24 @@ FilePath FilePath::pathAppended(const QString &path) const
FilePath fn = *this;
if (path.isEmpty())
return fn;
if (!fn.m_data.isEmpty() && !fn.m_data.endsWith(QLatin1Char('/')))
fn.m_data.append('/');
fn.m_data.append(path);
if (fn.m_data.isEmpty()) {
fn.m_data = path;
return fn;
}
if (fn.m_data.endsWith('/')) {
if (path.startsWith('/'))
fn.m_data.append(path.mid(1));
else
fn.m_data.append(path);
} else {
if (path.startsWith('/'))
fn.m_data.append(path);
else
fn.m_data.append('/').append(path);
}
return fn;
}