mirror of https://github.com/0xERR0R/blocky.git
fix: make domain validation in list parser more lenient
This commit is contained in:
parent
8253075f28
commit
ea95d36f37
1
go.mod
1
go.mod
|
@ -79,7 +79,6 @@ require (
|
|||
github.com/KyleBanks/depth v1.2.1 // indirect
|
||||
github.com/Masterminds/goutils v1.1.1 // indirect
|
||||
github.com/alicebob/gopher-json v0.0.0-20200520072559-a9ecdc9d1d3a // indirect
|
||||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d
|
||||
github.com/beorn7/perks v1.0.1 // indirect
|
||||
github.com/cespare/xxhash/v2 v2.1.2 // indirect
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.2 // indirect
|
||||
|
|
2
go.sum
2
go.sum
|
@ -62,8 +62,6 @@ github.com/alicebob/miniredis/v2 v2.30.1/go.mod h1:b25qWj4fCEsBeAAR2mlb0ufImGC6u
|
|||
github.com/antihax/optional v1.0.0/go.mod h1:uupD/76wgC+ih3iEmQUL+0Ugr19nfwCT1kdvxnR2qWY=
|
||||
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef h1:2JGTg6JapxP9/R33ZaagQtAM4EkkSYnIAlOG5EI8gkM=
|
||||
github.com/asaskevich/EventBus v0.0.0-20200907212545-49d423059eef/go.mod h1:JS7hed4L1fj0hXcyEejnW57/7LCetXggd+vwrRnYeII=
|
||||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d h1:Byv0BzEl3/e6D5CLfI0j/7hiIEtvGVFPCZ7Ei2oq8iQ=
|
||||
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d/go.mod h1:WaHUgvxTVq04UNunO+XhnAqY/wQc+bxr74GqbsZ/Jqw=
|
||||
github.com/avast/retry-go/v4 v4.3.3 h1:G56Bp6mU0b5HE1SkaoVjscZjlQb0oy4mezwY/cGH19w=
|
||||
github.com/avast/retry-go/v4 v4.3.3/go.mod h1:rg6XFaiuFYII0Xu3RDbZQkxCofFwruZKW8oEF1jpWiU=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
|
|
|
@ -10,14 +10,21 @@ import (
|
|||
"regexp"
|
||||
"strings"
|
||||
|
||||
"github.com/asaskevich/govalidator"
|
||||
"github.com/hashicorp/go-multierror"
|
||||
"golang.org/x/net/idna"
|
||||
)
|
||||
|
||||
const maxDomainNameLength = 255 // https://www.rfc-editor.org/rfc/rfc1034#section-3.1
|
||||
const (
|
||||
maxDomainNameLength = 255 // https://www.rfc-editor.org/rfc/rfc1034#section-3.1
|
||||
|
||||
var domainNameRegex = regexp.MustCompile(govalidator.DNSName)
|
||||
dnsLabelPattern = `[a-zA-Z0-9_-]{1,63}`
|
||||
)
|
||||
|
||||
// Validate a domain name, but with extra flexibility:
|
||||
// - no restriction on the start or end of labels
|
||||
//
|
||||
// https://www.rfc-editor.org/rfc/rfc1034#section-3.5
|
||||
var domainNameRegex = regexp.MustCompile(`^` + dnsLabelPattern + `(\.` + dnsLabelPattern + `)*[\._]?$`)
|
||||
|
||||
// Hosts parses `r` as a series of `HostsIterator`.
|
||||
// It supports both the hosts file and host list formats.
|
||||
|
|
|
@ -307,6 +307,10 @@ var _ = Describe("HostList", func() {
|
|||
|
||||
// Domain name w/ rune not supported by `idna.Lookup`
|
||||
"domain_underscore.tld",
|
||||
|
||||
// invalid domain names we want to support
|
||||
"-start-with-a-hyphen.com",
|
||||
"end-with-a-hyphen-.com",
|
||||
)
|
||||
})
|
||||
|
||||
|
@ -341,11 +345,21 @@ var _ = Describe("HostList", func() {
|
|||
Expect(entry.String()).Should(Equal("domain_underscore.tld"))
|
||||
Expect(sut.Position()).Should(Equal("line 8"))
|
||||
|
||||
entry, err = sut.Next(context.Background())
|
||||
Expect(err).Should(Succeed())
|
||||
Expect(entry.String()).Should(Equal("-start-with-a-hyphen.com"))
|
||||
Expect(sut.Position()).Should(Equal("line 9"))
|
||||
|
||||
entry, err = sut.Next(context.Background())
|
||||
Expect(err).Should(Succeed())
|
||||
Expect(entry.String()).Should(Equal("end-with-a-hyphen-.com"))
|
||||
Expect(sut.Position()).Should(Equal("line 10"))
|
||||
|
||||
_, err = sut.Next(context.Background())
|
||||
Expect(err).ShouldNot(Succeed())
|
||||
Expect(err).Should(MatchError(io.EOF))
|
||||
Expect(IsNonResumableErr(err)).Should(BeTrue())
|
||||
Expect(sut.Position()).Should(Equal("line 9"))
|
||||
Expect(sut.Position()).Should(Equal("line 11"))
|
||||
})
|
||||
})
|
||||
|
||||
|
|
Loading…
Reference in New Issue