fix_case_insensitive_addrs (#148)

Fixes #144

Co-authored-by: James Mills <prologic@shortcircuit.net.au>
Reviewed-on: #148
Reviewed-by: xuu <xuu@noreply@mills.io>
Co-authored-by: James Mills <james@mills.io>
Co-committed-by: James Mills <james@mills.io>
pull/153/head
James Mills 6 months ago committed by xuu
parent 832fb124fe
commit d90292bc8e
  1. 8
      cmd/salty-chat/avatar.go
  2. 8
      cmd/salty-chat/chat.go
  3. 7
      cmd/salty-chat/makeuser.go
  4. 8
      cmd/salty-chat/read.go
  5. 8
      cmd/salty-chat/register.go
  6. 7
      cmd/salty-chat/send.go
  7. 11
      identity.go
  8. BIN
      internal/web/app.wasm
  9. 2
      lookup.go

@ -3,7 +3,6 @@ package main
import (
"fmt"
"os"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@ -30,10 +29,9 @@ NOTE: This is only spported on a Salty Broker.`,
}
}
me := &saltyim.Addr{}
if sp := strings.Split(user, "@"); len(sp) > 1 {
me.User = sp[0]
me.Domain = sp[1]
me, err := saltyim.ParseAddr(user)
if err != nil {
fmt.Fprintf(os.Stderr, "error parsing addr: %s\n", err)
}
// XXX: What if me.IsZero()

@ -3,7 +3,6 @@ package main
import (
"fmt"
"os"
"strings"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
@ -34,10 +33,9 @@ messages to the user via their discovered endpoint.`,
}
}
me := &saltyim.Addr{}
if sp := strings.Split(user, "@"); len(sp) > 1 {
me.User = sp[0]
me.Domain = sp[1]
me, err := saltyim.ParseAddr(user)
if err != nil {
fmt.Fprintf(os.Stderr, "error parsing addr: %s\n", err)
}
// XXX: What if me.IsZero()

@ -68,10 +68,9 @@ NOTE: The <endpoint> argument will override and -u/--endpoint flag set.`,
endpoint = args[1]
}
me := &saltyim.Addr{}
if sp := strings.Split(args[0], "@"); len(sp) > 1 {
me.User = sp[0]
me.Domain = sp[1]
me, err := saltyim.ParseAddr(args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "error parsing addr: %s\n", err)
}
// XXX: What if me.IsZero()

@ -4,7 +4,6 @@ import (
"fmt"
"os"
"os/signal"
"strings"
"syscall"
"github.com/mattn/go-isatty"
@ -34,10 +33,9 @@ not specified defaults to the local user ($USER)`,
}
}
me := &saltyim.Addr{}
if sp := strings.Split(user, "@"); len(sp) > 1 {
me.User = sp[0]
me.Domain = sp[1]
me, err := saltyim.ParseAddr(user)
if err != nil {
fmt.Fprintf(os.Stderr, "error parsing addr: %s\n", err)
}
// XXX: What if me.IsZero()

@ -4,7 +4,6 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"github.com/spf13/cobra"
"github.com/spf13/viper"
@ -26,10 +25,9 @@ NOTE: This is only spported o a Salty Broker.`,
identity := viper.GetString("identity")
broker := viper.GetString("broker")
me := &saltyim.Addr{}
if sp := strings.Split(args[0], "@"); len(sp) > 1 {
me.User = sp[0]
me.Domain = sp[1]
me, err := saltyim.ParseAddr(args[0])
if err != nil {
fmt.Fprintf(os.Stderr, "error parsing addr: %s\n", err)
}
// XXX: What if me.IsZero()

@ -46,10 +46,9 @@ https://mills.io/.well-known/salty/prologic.json`,
}
}
me := &saltyim.Addr{}
if sp := strings.Split(user, "@"); len(sp) > 1 {
me.User = sp[0]
me.Domain = sp[1]
me, err := saltyim.ParseAddr(user)
if err != nil {
fmt.Fprintf(os.Stderr, "error parsing addr: %s\n", err)
}
// XXX: What if me.IsZero()

@ -17,18 +17,15 @@ import (
func readUser(fd io.Reader) (*Addr, error) {
scan := bufio.NewScanner(fd)
addr := &Addr{}
for scan.Scan() {
if strings.HasPrefix(scan.Text(), "# user:") {
user := strings.Split(strings.TrimSpace(strings.TrimPrefix(scan.Text(), "# user:")), "@")
if len(user) != 2 {
return nil, nil
addr, err := ParseAddr(strings.TrimSpace(strings.TrimPrefix(scan.Text(), "# user:")))
if err == nil {
return addr, nil
}
addr.User, addr.Domain = user[0], user[1]
}
}
return addr, scan.Err()
return nil, scan.Err()
}
// DefaultIdentity returns a default identity file (if one exists) otherwise

BIN
internal/web/app.wasm (Stored with Git LFS)

Binary file not shown.

@ -229,7 +229,7 @@ func (a *Addr) Avatar() string {
// parts and returns an Addr object with the User and Domain and a method
// for returning the expected User's Well-Known URI
func ParseAddr(addr string) (*Addr, error) {
parts := strings.Split(addr, "@")
parts := strings.Split(strings.ToLower(addr), "@")
if len(parts) != 2 {
return nil, fmt.Errorf("expected nick@domain found %q", addr)
}

Loading…
Cancel
Save