Commit dfd8e3c7 authored by Fabian Vogt's avatar Fabian Vogt

Fix lookup of files with special URL chars in their name

- Don't use those verbatim in the URL, escape them first
parent 347fdde1
......@@ -1078,8 +1078,8 @@ void KIOFuseVFS::lookup(fuse_req_t req, fuse_ino_t parent, const char *name)
if(auto child = that->nodeByName(parentNode, nodeName))
return that->replyEntry(req, child);
QUrl parentUrl = that->remoteUrl(parentNode);
if(parentUrl.isEmpty())
QUrl url = that->remoteUrl(parentNode);
if(url.isEmpty())
{
// Directory not remote, so definitely does not exist
fuse_reply_err(req, ENOENT);
......@@ -1087,7 +1087,8 @@ void KIOFuseVFS::lookup(fuse_req_t req, fuse_ino_t parent, const char *name)
}
// Not in the local tree, but remote - try again
that->mountUrl(QUrl(parentUrl.toString() + QLatin1Char('/') + nodeName), [=](auto node, int error) {
url.setPath(url.path() + QLatin1Char('/') + nodeName);
that->mountUrl(url, [=](auto node, int error) {
if(error && error != ENOENT)
fuse_reply_err(req, error);
else
......
......@@ -54,6 +54,7 @@ private Q_SLOTS:
void testArchiveOps();
void testKioErrorMapping();
void testRootLookup();
void testFilenameEscaping();
#ifdef WASTE_DISK_SPACE
void testReadWrite4GBFile();
#endif // WASTE_DISK_SPACE
......@@ -586,6 +587,34 @@ void FileOpsTest::testRootLookup()
QCOMPARE(errno, ENOENT);
}
void FileOpsTest::testFilenameEscaping()
{
QTemporaryDir localDir;
QVERIFY(localDir.isValid());
// Mount the temporary dir
QString reply = m_kiofuse_iface.mountUrl(QStringLiteral("file://%1").arg(localDir.path())).value();
QVERIFY(!reply.isEmpty());
QDir mirrorDir(reply);
QVERIFY(mirrorDir.exists());
// Create a file in localDir with an "unusual" filename
for(const QString &name : {QStringLiteral("file0?name"),
QStringLiteral("file1#name"), QStringLiteral("file2%20name"),
QStringLiteral("file2 \nname?asdf&foo#bar")})
{
QFile localFile(localDir.filePath(name));
QVERIFY(localFile.open(QFile::WriteOnly));
QCOMPARE(localFile.write("teststring", 10), 10);
localFile.close();
QFile mirrorFile(mirrorDir.filePath(name));
QVERIFY2(mirrorFile.open(QFile::ReadOnly), name.toUtf8().data());
QCOMPARE(mirrorFile.readAll(), QStringLiteral("teststring").toUtf8());
}
}
#ifdef WASTE_DISK_SPACE
void FileOpsTest::testReadWrite4GBFile()
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment