diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-07-21 11:19:10 +0200 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2020-07-21 18:26:23 +0200 |
commit | 6d804f56e570c39ea9967c66c4bdad6f530e956e (patch) | |
tree | 66fccba1411cea7356f41545b46267811bcc7df7 /lib | |
parent | 1529f46e6dd457d059fb7e6e9cd10fa0b0399553 (diff) | |
download | libquotient-6d804f56e570c39ea9967c66c4bdad6f530e956e.tar.gz libquotient-6d804f56e570c39ea9967c66c4bdad6f530e956e.zip |
Uri: bare-sigil URIs are invalid
Diffstat (limited to 'lib')
-rw-r--r-- | lib/uri.cpp | 24 |
1 files changed, 17 insertions, 7 deletions
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)); |