jid: Test for too many @ before the resourcepart

This additionally should optimize the parsing a tiny bit by looking for
both @ and / at the same time and iterating on them, instead of one by
one.

Thanks nicoco for the report!
This commit is contained in:
Emmanuel Gil Peyrot 2025-02-04 18:11:42 +01:00 committed by pep
commit f5f35eab20
3 changed files with 80 additions and 48 deletions

View file

@ -46,6 +46,9 @@ pub enum Error {
/// Happens when parsing a bare JID and there is a resource.
ResourceInBareJid,
/// Happens when parsing a JID which has two @ before the resource.
TooManyAts,
}
impl core::error::Error for Error {}
@ -64,6 +67,7 @@ impl fmt::Display for Error {
Error::ResourcePrep => "resource doesnt pass resourceprep validation",
Error::ResourceMissingInFullJid => "no resource found in this full JID",
Error::ResourceInBareJid => "resource found while parsing a bare JID",
Error::TooManyAts => "second @ found before parsing the resource",
})
}
}