diff --git a/CHANGELOG.md b/CHANGELOG.md index fc2d8bc..2fe2a6c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/jid.go b/jid.go index 95ff508..0c5e5be 100644 --- a/jid.go +++ b/jid.go @@ -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 }