Merge pull request #202 from mattn/fix/web-scheme-guessing

fetch, group: fix web address scheme guessing
This commit is contained in:
mattn
2026-08-23 16:59:17 +00:00
committed by GitHub
2 changed files with 16 additions and 2 deletions

View File

@@ -176,7 +176,16 @@ func isWebAddress(code string) bool {
func guessWebScheme(code string) string {
host, _, _ := strings.Cut(code, "/")
if strings.HasPrefix(host, "localhost") || strings.HasPrefix(host, "127.0.0.1") {
if strings.HasPrefix(host, "[") {
// ipv6 literal, keep only the bracketed part
if i := strings.Index(host, "]"); i != -1 {
host = host[:i+1]
}
} else if h, _, ok := strings.Cut(host, ":"); ok {
// strip port
host = h
}
if host == "localhost" || host == "127.0.0.1" || host == "[::1]" {
return "http://"
}
return "https://"

View File

@@ -1029,7 +1029,12 @@ func parseGroupIdentifier(ctx context.Context, c *cli.Command) (relay string, id
identifier = ptr.Identifier
author = ptr.PublicKey
} else if isWebAddress(groupArg) {
webPath, err := nipad.Resolve(ctx, groupArg)
addr := groupArg
if !strings.HasPrefix(addr, "http://") && !strings.HasPrefix(addr, "https://") {
addr = guessWebScheme(addr) + addr
}
webPath, err := nipad.Resolve(ctx, addr)
if err != nil {
return "", "", nostr.ZeroPK, fmt.Errorf("failed to resolve group address '%s': %w", groupArg, err)
}