From 90bf87760453c5fb32e6b135dfcfadc2d7700886 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Thu, 31 Dec 2020 15:16:46 +0900 Subject: Fixed handling of files containing an # in the name when using the system:/media or media:/ protocol. This resolves bug 3022 and bug 3063. Signed-off-by: Michele Calgaro --- tdeio/tdeio/kdirlister.cpp | 83 ++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 43 deletions(-) (limited to 'tdeio') diff --git a/tdeio/tdeio/kdirlister.cpp b/tdeio/tdeio/kdirlister.cpp index 1f3a03d1d..7b564f337 100644 --- a/tdeio/tdeio/kdirlister.cpp +++ b/tdeio/tdeio/kdirlister.cpp @@ -2355,25 +2355,24 @@ void KDirLister::handleError( TDEIO::Job *job ) void KDirLister::addNewItem( const KFileItem *item ) { - if ( ( d->dirOnlyMode && !item->isDir() ) || !matchesFilter( item ) ) { - return; // No reason to continue... bailing out here prevents a mimetype scan. - } - - if ((item->url().internalReferenceURL() != "") - && (d->m_referenceURLMap.contains(item->url().internalReferenceURL()))) { + TQString refURL = item->url().internalReferenceURL(); + if (!refURL.isEmpty() && d->m_referenceURLMap.contains(refURL) && + item->url().path().startsWith(d->m_referenceURLMap[refURL])) + { // Likely a media:/ tdeioslave URL or similar // Rewrite the URL to ensure that the user remains within the media:/ tree! - TQString itemPath = item->url().path(); - if (itemPath.startsWith(d->m_referenceURLMap[item->url().internalReferenceURL()])) { - itemPath = itemPath.remove(0, d->m_referenceURLMap[item->url().internalReferenceURL()].length()); - TQString newPath = item->url().internalReferenceURL(); - if (!newPath.endsWith("/")) newPath = newPath + "/"; - while (itemPath.startsWith("/")) itemPath = itemPath.remove(0,1); - while (itemPath.endsWith("/")) itemPath.truncate(itemPath.length()-1); - newPath = newPath + itemPath; - const_cast(item)->setListerURL(item->url()); - const_cast(item)->setURL(newPath); + if (!refURL.endsWith("/")) + { + refURL.append("/"); } + KURL newItemURL(refURL); + newItemURL.addPath(item->url().fileName()); + const_cast(item)->setListerURL(newItemURL); + const_cast(item)->setURL(newItemURL); + } + + if ( ( d->dirOnlyMode && !item->isDir() ) || !matchesFilter( item ) ) { + return; // No reason to continue... bailing out here prevents a mimetype scan. } if ( matchesMimeFilter( item ) ) @@ -2420,21 +2419,20 @@ void KDirLister::addRefreshItem( const KFileItem *item ) { bool isExcluded = (d->dirOnlyMode && !item->isDir()) || !matchesFilter( item ); - if ((item->url().internalReferenceURL() != "") - && (d->m_referenceURLMap.contains(item->url().internalReferenceURL()))) { + TQString refURL = item->url().internalReferenceURL(); + if (!refURL.isEmpty() && d->m_referenceURLMap.contains(refURL) && + item->url().path().startsWith(d->m_referenceURLMap[refURL])) + { // Likely a media:/ tdeioslave URL or similar // Rewrite the URL to ensure that the user remains within the media:/ tree! - TQString itemPath = item->url().path(); - if (itemPath.startsWith(d->m_referenceURLMap[item->url().internalReferenceURL()])) { - itemPath = itemPath.remove(0, d->m_referenceURLMap[item->url().internalReferenceURL()].length()); - TQString newPath = item->url().internalReferenceURL(); - if (!newPath.endsWith("/")) newPath = newPath + "/"; - while (itemPath.startsWith("/")) itemPath = itemPath.remove(0,1); - while (itemPath.endsWith("/")) itemPath.truncate(itemPath.length()-1); - newPath = newPath + itemPath; - const_cast(item)->setListerURL(item->url()); - const_cast(item)->setURL(newPath); + if (!refURL.endsWith("/")) + { + refURL.append("/"); } + KURL newItemURL(refURL); + newItemURL.addPath(item->url().fileName()); + const_cast(item)->setListerURL(newItemURL); + const_cast(item)->setURL(newItemURL); } if ( !isExcluded && matchesMimeFilter( item ) ) @@ -2658,25 +2656,24 @@ void KDirLister::connectJob( TDEIO::ListJob *job ) void KDirLister::emitCompleted( const KURL& _url ) { - KURL emitURL = _url; - - if ((_url.internalReferenceURL() != "") - && (d->m_referenceURLMap.contains(_url.internalReferenceURL()))) { + TQString refURL = _url.internalReferenceURL(); + if (!refURL.isEmpty() && d->m_referenceURLMap.contains(refURL) && + _url.path().startsWith(d->m_referenceURLMap[refURL])) + { // Likely a media:/ tdeioslave URL or similar // Rewrite the URL to ensure that the user remains within the media:/ tree! - TQString itemPath = _url.path(); - if (itemPath.startsWith(d->m_referenceURLMap[_url.internalReferenceURL()])) { - itemPath = itemPath.remove(0, d->m_referenceURLMap[_url.internalReferenceURL()].length()); - TQString newPath = _url.internalReferenceURL(); - if (!newPath.endsWith("/")) newPath = newPath + "/"; - while (itemPath.startsWith("/")) itemPath = itemPath.remove(0,1); - while (itemPath.endsWith("/")) itemPath.truncate(itemPath.length()-1); - newPath = newPath + itemPath; - emitURL = newPath; + if (!refURL.endsWith("/")) + { + refURL.append("/"); } + KURL newItemURL(refURL); + newItemURL.addPath(_url.fileName()); + emit completed(newItemURL); + } + else + { + emit completed(_url); } - - emit completed( emitURL ); } void KDirLister::setMainWindow( TQWidget *window ) -- cgit v1.2.1