Allow JIDs without localpart.

This commit is contained in:
Martin Dosch 2023-03-02 20:28:51 +01:00
parent 847e816266
commit 062614ee7a
No known key found for this signature in database
GPG Key ID: 52A57CFCE13D657D
2 changed files with 13 additions and 5 deletions

View File

@ -7,6 +7,7 @@
### Changed
- Print `--help` output to stdout instead of stderr.
- Print sent stanzas when `--debug` is used (via go-xmpp commit 9129a110df1b).
- Allow JIDs without localpart.
## [v0.5.6] 2022-11-11
### Added

17
jid.go
View File

@ -50,7 +50,7 @@ func MarshalJID(input string) (string, error) {
switch {
case sep == -1:
// There is no @ sign, and therefore no localpart.
return input, errors.New("Invalid JID: " + input)
domainpart = s
case sep == 0:
// The JID starts with an @ sign (invalid empty localpart)
err = errors.New("Invalid JID:" + input)
@ -71,17 +71,24 @@ func MarshalJID(input string) (string, error) {
// are taken.
domainpart = strings.TrimSuffix(domainpart, ".")
var jid string
if !utf8.ValidString(localpart) || !utf8.ValidString(domainpart) || !utf8.ValidString(resourcepart) {
return input, errors.New("Invalid JID: " + input)
}
if localpart == "" || domainpart == "" {
if domainpart == "" {
return input, errors.New("Invalid JID: " + input)
}
if resourcepart == "" {
return localpart + "@" + domainpart, err
if localpart == "" {
jid = domainpart
} else {
jid = localpart + "@" + domainpart
}
return localpart + "@" + domainpart + "/" + resourcepart, err
if resourcepart == "" {
return jid, err
}
return jid + "/" + resourcepart, err
}