Skip to content

Commit

Permalink
Allow TLD in and
Browse files Browse the repository at this point in the history
  • Loading branch information
ameshkov committed Apr 26, 2021
1 parent a616ee4 commit 04195dd
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
2 changes: 0 additions & 2 deletions filterutil/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func ExtractHostname(url string) string {
// . max length of ascii hostname including dots is 253 characters
// . TLD is >=2 characters
// . TLD is [a-zA-Z]+ or "xn--[a-zA-Z0-9]+"
// . at least 1 level above TLD Source
// nolint(gocyclo)
func IsDomainName(name string) bool {
if len(name) > 253 {
Expand Down Expand Up @@ -129,7 +128,6 @@ func IsDomainName(name string) bool {

if st != 2 ||
nLabel == 1 ||
nLevel == 1 ||
(!charOnly && xn < len("xn--wwww")) {
return false
}
Expand Down
4 changes: 2 additions & 2 deletions filterutil/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ func TestIsDomainName(t *testing.T) {
assert.True(t, IsDomainName("abc.xn--p1ai"))
assert.True(t, IsDomainName("xn--p1ai.xn--p1ai"))
assert.True(t, IsDomainName("123456789012345678901234567890123456789012345678901234567890123.cc"))

assert.False(t, IsDomainName("cc"))
assert.True(t, IsDomainName("cc"))
assert.True(t, IsDomainName("xn--p1ai"))

assert.False(t, IsDomainName("#cc"))
assert.False(t, IsDomainName("a.cc#"))
Expand Down
7 changes: 7 additions & 0 deletions rules/network_rule_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -406,6 +406,13 @@ func TestNetworkRule_Denyallow(t *testing.T) {
ruleText: "*^$denyallow",
fail: true,
},
{
testName: "denyallow_unblock_tld",
ruleText: "*^$denyallow=org",
requestURL: "https://example.org/",
fail: false,
match: false,
},
{
testName: "denyallow_found",
ruleText: "*^$denyallow=example.org",
Expand Down

0 comments on commit 04195dd

Please sign in to comment.