diff --git a/assignment-client/src/assets/AssetServer.cpp b/assignment-client/src/assets/AssetServer.cpp index 905cc6fd30..2fbe2f6dfe 100644 --- a/assignment-client/src/assets/AssetServer.cpp +++ b/assignment-client/src/assets/AssetServer.cpp @@ -453,7 +453,7 @@ bool AssetServer::loadMappingsFromFile() { while (it != _fileMappings.end()) { bool shouldDrop = false; - if (!isValidPath(it.key())) { + if (!isValidFilePath(it.key())) { qWarning() << "Will not keep mapping for" << it.key() << "since it is not a valid path."; shouldDrop = true; } @@ -508,7 +508,7 @@ bool AssetServer::writeMappingsToFile() { bool AssetServer::setMapping(AssetPath path, AssetHash hash) { path = path.trimmed(); - if (!isValidPath(path)) { + if (!isValidFilePath(path)) { qWarning() << "Cannot set a mapping for invalid path:" << path << "=>" << hash; return false; } @@ -637,8 +637,8 @@ bool AssetServer::renameMapping(AssetPath oldPath, AssetPath newPath) { oldPath = oldPath.trimmed(); newPath = newPath.trimmed(); - if (!isValidPath(oldPath) || !isValidPath(newPath)) { - qWarning() << "Cannot perform rename with invalid paths - both should have leading forward slashes:" + if (!isValidFilePath(oldPath) || !isValidFilePath(newPath)) { + qWarning() << "Cannot perform rename with invalid paths - both should have leading forward and no ending slashes:" << oldPath << "=>" << newPath; return false; diff --git a/interface/resources/qml/AssetServer.qml b/interface/resources/qml/AssetServer.qml index ec866a6f0e..cf61a2ae4a 100644 --- a/interface/resources/qml/AssetServer.qml +++ b/interface/resources/qml/AssetServer.qml @@ -349,7 +349,7 @@ ScrollingWindow { }, function(err, path) { print(err, path); - if (!err) { + if (err === "") { uploadProgressLabel.text = "Upload Complete"; timer.interval = 1000; timer.repeat = false; @@ -362,14 +362,15 @@ ScrollingWindow { console.log("Asset Browser - finished uploading: ", fileUrl); reload(); } else { - if (err > 0) { - console.log("Asset Browser - error uploading: ", fileUrl, " - error ", err); - var box = errorMessageBox("There was an error uploading:\n" + fileUrl + "\n" + Assets.getErrorString(err)); - box.selected.connect(reload); - } uploadSpinner.visible = false; uploadButton.enabled = true; uploadOpen = false; + + if (err !== -1) { + console.log("Asset Browser - error uploading: ", fileUrl, " - error ", err); + var box = errorMessageBox("There was an error uploading:\n" + fileUrl + "\n" + err); + box.selected.connect(reload); + } } }, dropping); } diff --git a/libraries/networking/src/AssetUtils.cpp b/libraries/networking/src/AssetUtils.cpp index c505d108e5..7818c8e5ce 100644 --- a/libraries/networking/src/AssetUtils.cpp +++ b/libraries/networking/src/AssetUtils.cpp @@ -70,6 +70,11 @@ bool saveToCache(const QUrl& url, const QByteArray& file) { return false; } +bool isValidFilePath(const AssetPath& filePath) { + QRegExp filePathRegex { ASSET_FILE_PATH_REGEX_STRING }; + return filePathRegex.exactMatch(filePath); +} + bool isValidPath(const AssetPath& path) { QRegExp pathRegex { ASSET_PATH_REGEX_STRING }; return pathRegex.exactMatch(path); diff --git a/libraries/networking/src/AssetUtils.h b/libraries/networking/src/AssetUtils.h index 3a663af420..9e508418ab 100644 --- a/libraries/networking/src/AssetUtils.h +++ b/libraries/networking/src/AssetUtils.h @@ -31,7 +31,8 @@ const size_t SHA256_HASH_LENGTH = 32; const size_t SHA256_HASH_HEX_LENGTH = 64; const uint64_t MAX_UPLOAD_SIZE = 1000 * 1000 * 1000; // 1GB -const QString ASSET_PATH_REGEX_STRING = "^\\/(?!\\/)(?:[^\\/]|\\/(?!\\/))*$"; +const QString ASSET_FILE_PATH_REGEX_STRING = "^(\\/[^\\/\\0]+)+$"; +const QString ASSET_PATH_REGEX_STRING = "^\\/([^\\/\\0]+(\\/)?)+$"; const QString ASSET_HASH_REGEX_STRING = QString("^[a-fA-F0-9]{%1}$").arg(SHA256_HASH_HEX_LENGTH); enum AssetServerError : uint8_t { @@ -59,6 +60,7 @@ QByteArray hashData(const QByteArray& data); QByteArray loadFromCache(const QUrl& url); bool saveToCache(const QUrl& url, const QByteArray& file); +bool isValidFilePath(const AssetPath& path); bool isValidPath(const AssetPath& path); bool isValidHash(const QString& hashString); diff --git a/libraries/networking/src/MappingRequest.cpp b/libraries/networking/src/MappingRequest.cpp index d3950f9f30..62a60c521b 100644 --- a/libraries/networking/src/MappingRequest.cpp +++ b/libraries/networking/src/MappingRequest.cpp @@ -57,7 +57,7 @@ GetMappingRequest::GetMappingRequest(const AssetPath& path) : _path(path.trimmed void GetMappingRequest::doStart() { // short circuit the request if the path is invalid - if (!isValidPath(_path)) { + if (!isValidFilePath(_path)) { _error = MappingRequest::InvalidPath; emit finished(this); return; @@ -139,7 +139,7 @@ SetMappingRequest::SetMappingRequest(const AssetPath& path, const AssetHash& has void SetMappingRequest::doStart() { // short circuit the request if the hash or path are invalid - auto validPath = isValidPath(_path); + auto validPath = isValidFilePath(_path); auto validHash = isValidHash(_hash); if (!validPath || !validHash) { _error = !validPath ? MappingRequest::InvalidPath : MappingRequest::InvalidHash; @@ -226,7 +226,7 @@ RenameMappingRequest::RenameMappingRequest(const AssetPath& oldPath, const Asset void RenameMappingRequest::doStart() { // short circuit the request if either of the paths are invalid - if (!isValidPath(_oldPath) || !isValidPath(_newPath)) { + if (!isValidFilePath(_oldPath) || !isValidFilePath(_newPath)) { _error = InvalidPath; emit finished(this); return;