fix blank case on NormalizeURL().

This commit is contained in:
fiatjaf 2022-11-19 07:19:10 -03:00
parent 89cb5ad461
commit b2885d57cd
No known key found for this signature in database
GPG Key ID: BAD43C4BE5C1A3A1
2 changed files with 6 additions and 0 deletions

View File

@ -6,6 +6,10 @@ import (
)
func NormalizeURL(u string) string {
if u == "" {
return ""
}
if !strings.HasPrefix(u, "http") && !strings.HasPrefix(u, "ws") {
u = "wss://" + u
}

View File

@ -3,6 +3,7 @@ package nostr
import "fmt"
func ExampleNormalizeURL() {
fmt.Println(NormalizeURL(""))
fmt.Println(NormalizeURL("wss://x.com/y"))
fmt.Println(NormalizeURL("wss://x.com/y/"))
fmt.Println(NormalizeURL("http://x.com/y"))
@ -16,6 +17,7 @@ func ExampleNormalizeURL() {
fmt.Println(NormalizeURL("x.com/?x=23"))
// Output:
//
// wss://x.com/y
// wss://x.com/y
// ws://x.com/y