From 6d804f56e570c39ea9967c66c4bdad6f530e956e Mon Sep 17 00:00:00 2001 From: Kitsune Ral Date: Tue, 21 Jul 2020 11:19:10 +0200 Subject: Uri: bare-sigil URIs are invalid --- lib/uri.cpp | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'lib') diff --git a/lib/uri.cpp b/lib/uri.cpp index e81933dc..f813794c 100644 --- a/lib/uri.cpp +++ b/lib/uri.cpp @@ -7,12 +7,15 @@ using namespace Quotient; struct ReplacePair { QByteArray uriString; char sigil; }; -static const auto replacePairs = { ReplacePair { "user/", '@' }, - { "roomid/", '!' }, - { "room/", '#' }, - // The notation for bare event ids is not - // proposed in MSC2312 (and anywhere, as yet) - { "event/", '$' } }; +/// Defines bi-directional mapping of path prefixes and sigils +static const auto replacePairs = { + ReplacePair { "user/", '@' }, + { "roomid/", '!' }, + { "room/", '#' }, + // The notation for bare event ids is not proposed in MSC2312 but there's + // https://github.com/matrix-org/matrix-doc/pull/2644 + { "event/", '$' } +}; Uri::Uri(QByteArray primaryId, QByteArray secondaryId, QString query) { @@ -22,14 +25,21 @@ Uri::Uri(QByteArray primaryId, QByteArray secondaryId, QString query) setScheme("matrix"); QString pathToBe; primaryType_ = Invalid; + if (primaryId.size() < 2) // There should be something after sigil + return; for (const auto& p: replacePairs) if (primaryId[0] == p.sigil) { primaryType_ = Type(p.sigil); pathToBe = p.uriString + primaryId.mid(1); break; } - if (!secondaryId.isEmpty()) + if (!secondaryId.isEmpty()) { + if (secondaryId.size() < 2) { + primaryType_ = Invalid; + return; + } pathToBe += "/event/" + secondaryId.mid(1); + } setPath(pathToBe); } setQuery(std::move(query)); -- cgit v1.2.3