Fix: satisfy RFC4343 - DNS case insensitivity (#2260)
This commit is contained in:
parent
e96e586a37
commit
541943fd29
2 changed files with 25 additions and 0 deletions
|
@ -3,6 +3,7 @@ package fakeip
|
|||
import (
|
||||
"errors"
|
||||
"net"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"github.com/Dreamacro/clash/common/cache"
|
||||
|
@ -36,6 +37,9 @@ type Pool struct {
|
|||
func (p *Pool) Lookup(host string) net.IP {
|
||||
p.mux.Lock()
|
||||
defer p.mux.Unlock()
|
||||
|
||||
// RFC4343: DNS Case Insensitive, we SHOULD return result with all cases.
|
||||
host = strings.ToLower(host)
|
||||
if ip, exist := p.store.GetByHost(host); exist {
|
||||
return ip
|
||||
}
|
||||
|
|
|
@ -75,6 +75,27 @@ func TestPool_Basic(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPool_Case_Insensitive(t *testing.T) {
|
||||
_, ipnet, _ := net.ParseCIDR("192.168.0.1/29")
|
||||
pools, tempfile, err := createPools(Options{
|
||||
IPNet: ipnet,
|
||||
Size: 10,
|
||||
})
|
||||
assert.Nil(t, err)
|
||||
defer os.Remove(tempfile)
|
||||
|
||||
for _, pool := range pools {
|
||||
first := pool.Lookup("foo.com")
|
||||
last := pool.Lookup("Foo.Com")
|
||||
foo, exist := pool.LookBack(last)
|
||||
|
||||
assert.True(t, first.Equal(pool.Lookup("Foo.Com")))
|
||||
assert.Equal(t, pool.Lookup("fOo.cOM"), first)
|
||||
assert.True(t, exist)
|
||||
assert.Equal(t, foo, "foo.com")
|
||||
}
|
||||
}
|
||||
|
||||
func TestPool_CycleUsed(t *testing.T) {
|
||||
_, ipnet, _ := net.ParseCIDR("192.168.0.1/29")
|
||||
pools, tempfile, err := createPools(Options{
|
||||
|
|
Loading…
Reference in a new issue