mirror of
https://github.com/ergochat/ergo.git
synced 2024-11-10 22:19:31 +01:00
Merge pull request #332 from slingamn/rtlnickmasks
fix spurious bidi violations when casefolding the nickmask of an RTL nick
This commit is contained in:
commit
a11486d699
@ -98,6 +98,7 @@ type Client struct {
|
||||
socket *Socket
|
||||
stateMutex sync.RWMutex // tier 1
|
||||
username string
|
||||
usernameCasefolded string
|
||||
vhost string
|
||||
history *history.Buffer
|
||||
}
|
||||
@ -175,10 +176,11 @@ func NewClient(server *Server, conn net.Conn, isTLS bool) {
|
||||
resp, err := ident.Query(clientHost, serverPort, clientPort, IdentTimeoutSeconds)
|
||||
if err == nil {
|
||||
username := resp.Identifier
|
||||
_, err := CasefoldName(username) // ensure it's a valid username
|
||||
cfusername, err := CasefoldName(username)
|
||||
if err == nil {
|
||||
client.Notice(client.t("*** Found your username"))
|
||||
client.username = username
|
||||
client.usernameCasefolded = cfusername
|
||||
// we don't need to updateNickMask here since nickMask is not used for anything yet
|
||||
} else {
|
||||
client.Notice(client.t("*** Got a malformed username, ignoring"))
|
||||
@ -619,7 +621,7 @@ func (client *Client) HasUsername() bool {
|
||||
}
|
||||
|
||||
func (client *Client) SetNames(username, realname string) error {
|
||||
_, err := CasefoldName(username)
|
||||
usernameCasefolded, err := CasefoldName(username)
|
||||
if err != nil {
|
||||
return errInvalidUsername
|
||||
}
|
||||
@ -629,6 +631,7 @@ func (client *Client) SetNames(username, realname string) error {
|
||||
|
||||
if client.username == "" {
|
||||
client.username = "~" + username
|
||||
client.usernameCasefolded = "~" + usernameCasefolded
|
||||
}
|
||||
|
||||
if client.realname == "" {
|
||||
@ -759,48 +762,45 @@ func (client *Client) updateNickMaskNoMutex() {
|
||||
client.hostname = client.rawHostname
|
||||
}
|
||||
|
||||
nickMaskString := fmt.Sprintf("%s!%s@%s", client.nick, client.username, client.hostname)
|
||||
nickMaskCasefolded, err := Casefold(nickMaskString)
|
||||
cfhostname, err := Casefold(client.hostname)
|
||||
if err != nil {
|
||||
client.server.logger.Error("internal", "nickmask couldn't be casefolded", nickMaskString, err.Error())
|
||||
return
|
||||
client.server.logger.Error("internal", "hostname couldn't be casefolded", client.hostname, err.Error())
|
||||
cfhostname = client.hostname // YOLO
|
||||
}
|
||||
|
||||
client.nickMaskString = nickMaskString
|
||||
client.nickMaskCasefolded = nickMaskCasefolded
|
||||
client.nickMaskString = fmt.Sprintf("%s!%s@%s", client.nick, client.username, client.hostname)
|
||||
client.nickMaskCasefolded = fmt.Sprintf("%s!%s@%s", client.nickCasefolded, client.usernameCasefolded, cfhostname)
|
||||
}
|
||||
|
||||
// AllNickmasks returns all the possible nickmasks for the client.
|
||||
func (client *Client) AllNickmasks() []string {
|
||||
var masks []string
|
||||
var mask string
|
||||
var err error
|
||||
|
||||
func (client *Client) AllNickmasks() (masks []string) {
|
||||
client.stateMutex.RLock()
|
||||
nick := client.nick
|
||||
username := client.username
|
||||
nick := client.nickCasefolded
|
||||
username := client.usernameCasefolded
|
||||
rawHostname := client.rawHostname
|
||||
vhost := client.getVHostNoMutex()
|
||||
client.stateMutex.RUnlock()
|
||||
|
||||
if len(vhost) > 0 {
|
||||
mask, err = Casefold(fmt.Sprintf("%s!%s@%s", nick, username, vhost))
|
||||
cfvhost, err := Casefold(vhost)
|
||||
if err == nil {
|
||||
masks = append(masks, mask)
|
||||
masks = append(masks, fmt.Sprintf("%s!%s@%s", nick, username, cfvhost))
|
||||
}
|
||||
}
|
||||
|
||||
mask, err = Casefold(fmt.Sprintf("%s!%s@%s", nick, username, rawHostname))
|
||||
var rawhostmask string
|
||||
cfrawhost, err := Casefold(rawHostname)
|
||||
if err == nil {
|
||||
masks = append(masks, mask)
|
||||
rawhostmask = fmt.Sprintf("%s!%s@%s", nick, username, cfrawhost)
|
||||
masks = append(masks, rawhostmask)
|
||||
}
|
||||
|
||||
mask2, err := Casefold(fmt.Sprintf("%s!%s@%s", nick, username, client.IPString()))
|
||||
if err == nil && mask2 != mask {
|
||||
masks = append(masks, mask2)
|
||||
ipmask := fmt.Sprintf("%s!%s@%s", nick, username, client.IPString())
|
||||
if ipmask != rawhostmask {
|
||||
masks = append(masks, ipmask)
|
||||
}
|
||||
|
||||
return masks
|
||||
return
|
||||
}
|
||||
|
||||
// LoggedIntoAccount returns true if this client is logged into an account.
|
||||
|
Loading…
Reference in New Issue
Block a user