mirror of
https://github.com/nbd-wtf/go-nostr.git
synced 2025-10-04 17:40:04 +02:00
fix normalize and add a test.
This commit is contained in:
@@ -20,9 +20,7 @@ func NormalizeURL(u string) string {
|
||||
p.Scheme = "wss"
|
||||
}
|
||||
|
||||
if strings.HasSuffix(p.RawPath, "/") {
|
||||
p.RawPath = p.RawPath[0 : len(p.RawPath)-1]
|
||||
}
|
||||
p.Path = strings.TrimRight(p.Path, "/")
|
||||
|
||||
return p.String()
|
||||
}
|
||||
|
30
normalize_test.go
Normal file
30
normalize_test.go
Normal file
@@ -0,0 +1,30 @@
|
||||
package nostr
|
||||
|
||||
import "fmt"
|
||||
|
||||
func ExampleNormalizeURL() {
|
||||
fmt.Println(NormalizeURL("wss://x.com/y"))
|
||||
fmt.Println(NormalizeURL("wss://x.com/y/"))
|
||||
fmt.Println(NormalizeURL("http://x.com/y"))
|
||||
fmt.Println(NormalizeURL(NormalizeURL("http://x.com/y")))
|
||||
fmt.Println(NormalizeURL("wss://x.com"))
|
||||
fmt.Println(NormalizeURL("wss://x.com/"))
|
||||
fmt.Println(NormalizeURL(NormalizeURL(NormalizeURL("wss://x.com/"))))
|
||||
fmt.Println(NormalizeURL("x.com"))
|
||||
fmt.Println(NormalizeURL("x.com/"))
|
||||
fmt.Println(NormalizeURL("x.com////"))
|
||||
fmt.Println(NormalizeURL("x.com/?x=23"))
|
||||
|
||||
// Output:
|
||||
// wss://x.com/y
|
||||
// wss://x.com/y
|
||||
// ws://x.com/y
|
||||
// ws://x.com/y
|
||||
// wss://x.com
|
||||
// wss://x.com
|
||||
// wss://x.com
|
||||
// wss://x.com
|
||||
// wss://x.com
|
||||
// wss://x.com
|
||||
// wss://x.com?x=23
|
||||
}
|
Reference in New Issue
Block a user