mirror of
https://github.com/tinyauthapp/tinyauth.git
synced 2026-08-31 02:23:31 +08:00
fix: no need for idna conversion in domain validator
This commit is contained in:
@@ -38,7 +38,16 @@ func SafeParseAppURL(str string) (string, error) {
|
||||
return "", fmt.Errorf("ip addresses not allowed")
|
||||
}
|
||||
|
||||
hostname, err = idna.Lookup.ToASCII(hostname)
|
||||
i := idna.New(
|
||||
idna.MapForLookup(),
|
||||
idna.Transitional(false),
|
||||
idna.BidiRule(),
|
||||
idna.StrictDomainName(false),
|
||||
idna.CheckHyphens(true),
|
||||
idna.CheckJoiners(false),
|
||||
)
|
||||
|
||||
hostname, err = i.ToASCII(hostname)
|
||||
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to convert hostname to ascii: %w", err)
|
||||
|
||||
@@ -43,6 +43,13 @@ func TestSafeParseAPPURL(t *testing.T) {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expected, result)
|
||||
|
||||
// Underscores
|
||||
appURL = "http://sub_tinyauth.app"
|
||||
expected = "http://sub_tinyauth.app"
|
||||
result, err = utils.SafeParseAppURL(appURL)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, expected, result)
|
||||
|
||||
// Lowercase
|
||||
appURL = "HTTP://SUb.tinyAUth.aPP"
|
||||
expected = "http://sub.tinyauth.app"
|
||||
@@ -66,7 +73,7 @@ func TestSafeParseAPPURL(t *testing.T) {
|
||||
assert.ErrorContains(t, err, "invalid url")
|
||||
|
||||
// Invalid punycode
|
||||
appURL = "http://ab--cd.example.com"
|
||||
appURL = "http://xn--h-kva.example.com"
|
||||
_, err = utils.SafeParseAppURL(appURL)
|
||||
assert.ErrorContains(t, err, "failed to convert hostname to ascii")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user