fix and use a supposedly much faster library on NormalizeURL(), it's slightly less tolerant with stupidly-formed URLs.

This commit is contained in:
fiatjaf
2025-02-25 09:55:19 -03:00
parent 7e06354b6f
commit 6d8cd55784
4 changed files with 49 additions and 17 deletions

View File

@@ -1,9 +1,10 @@
package nostr
import (
"strconv"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
type urlTest struct {
@@ -21,17 +22,19 @@ var urlTests = []urlTest{
{NormalizeURL(NormalizeURL(NormalizeURL("wss://x.com/"))), "wss://x.com"},
{"wss://x.com", "wss://x.com"},
{"wss://x.com/", "wss://x.com"},
{"x.com////", "wss://x.com"},
{"x.com/?x=23", "wss://x.com?x=23"},
{"localhost:4036", "ws://localhost:4036"},
{"localhost:4036/relay", "ws://localhost:4036/relay"},
{"localhostmagnanimus.com", "wss://localhostmagnanimus.com"},
{NormalizeURL("localhost:4036/relay"), "ws://localhost:4036/relay"},
{NormalizeURL("nostr:askjd"), "nostr://askjd"},
}
func TestNormalizeURL(t *testing.T) {
for _, test := range urlTests {
output := NormalizeURL(test.url)
assert.Equal(t, test.expected, output)
for i, test := range urlTests {
t.Run(strconv.Itoa(i)+" { "+test.url+" -> "+test.expected+" }", func(t *testing.T) {
output := NormalizeURL(test.url)
require.Equal(t, test.expected, output)
})
}
}