mirror of
https://salsa.debian.org/mdosch/go-sendxmpp
synced 2024-11-18 21:25:31 +00:00
Allow JIDs without localpart.
This commit is contained in:
parent
847e816266
commit
062614ee7a
@ -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
17
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user