Fix loading avatars from Dropbox due to URLs containing parameters

This commit is contained in:
Dale Glass 2023-09-18 20:22:58 +02:00
parent 375538140d
commit 0fb11f1dcb

View file

@ -20,6 +20,9 @@
#include <NetworkingConstants.h>
#include <SharedUtil.h>
const QStringList SINGLE_VALUE_PROPERTIES{"name", "filename", "texdir", "script", "comment"};
hifi::VariantMultiHash FSTReader::parseMapping(QIODevice* device) {
hifi::VariantMultiHash properties;
@ -32,9 +35,25 @@ hifi::VariantMultiHash FSTReader::parseMapping(QIODevice* device) {
if (sections.size() < 2) {
continue;
}
// We can have URLs like:
// filename = https://www.dropbox.com/scl/fi/xxx/avatar.fbx?rlkey=xxx&dl=1\n
// These confuse the parser due to the presence of = in the URL.
//
// SINGLE_VALUE_PROPERTIES contains a list of things that may be URLs or contain an =
// for some other reason, and that we know for sure contain only a single value after
// the first =.
//
// Really though, we should just use JSON instead.
QByteArray name = sections.at(0).trimmed();
if (sections.size() == 2) {
properties.insert(name, sections.at(1).trimmed());
bool isSingleValue = SINGLE_VALUE_PROPERTIES.contains(name);
if (sections.size() == 2 || isSingleValue) {
// As per the above, we can have '=' signs inside of URLs, so instead of
// using the split string, just use everything after the first '='.
QString value = line.mid(line.indexOf("=")+1).trimmed();
properties.insert(name, value);
} else if (sections.size() == 3) {
QVariantHash heading = properties.value(name).toHash();
heading.insert(sections.at(1).trimmed(), sections.at(2).trimmed());