Updates publicsuffix-go to upstream idna branch.
This commit bumps the publicsuffix-go dependency to the WIP branch from https://github.com/weppos/publicsuffix-go/pull/40 to support IDN TLDs.
This commit is contained in:
parent
595204b23f
commit
c5cc328b11
|
@ -198,7 +198,8 @@
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "github.com/weppos/publicsuffix-go/publicsuffix",
|
"ImportPath": "github.com/weppos/publicsuffix-go/publicsuffix",
|
||||||
"Rev": "3316aa3feceb68fa73009112eddd387500cd40c0"
|
"Comment": "v0.2.0-7-g7c78f35",
|
||||||
|
"Rev": "7c78f3583bc3ab1ccf4ac5fdf70797aaacf52615"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"ImportPath": "golang.org/x/crypto/ocsp",
|
"ImportPath": "golang.org/x/crypto/ocsp",
|
||||||
|
|
|
@ -11,9 +11,16 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"golang.org/x/net/idna"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
// Version identifies the current library version.
|
||||||
|
// This is a pro-forma convention given that Go dependencies
|
||||||
|
// tends to be fetched directly from the repo.
|
||||||
|
Version = "0.2.0"
|
||||||
|
|
||||||
NormalType = 1
|
NormalType = 1
|
||||||
WildcardType = 2
|
WildcardType = 2
|
||||||
ExceptionType = 3
|
ExceptionType = 3
|
||||||
|
@ -26,10 +33,10 @@ const (
|
||||||
var DefaultList = NewList()
|
var DefaultList = NewList()
|
||||||
|
|
||||||
// DefaultRule is the default Rule that represents "*".
|
// DefaultRule is the default Rule that represents "*".
|
||||||
var DefaultRule = NewRule("*")
|
var DefaultRule = MustNewRule("*")
|
||||||
|
|
||||||
// DefaultParserOptions are the default options used to parse a Public Suffix list.
|
// DefaultParserOptions are the default options used to parse a Public Suffix list.
|
||||||
var DefaultParserOptions = &ParserOption{PrivateDomains: true}
|
var DefaultParserOptions = &ParserOption{PrivateDomains: true, ASCIIEncoded: false}
|
||||||
|
|
||||||
// DefaultFindOptions are the default options used to perform the lookup of rules in the list.
|
// DefaultFindOptions are the default options used to perform the lookup of rules in the list.
|
||||||
var DefaultFindOptions = &FindOptions{IgnorePrivate: false, DefaultRule: DefaultRule}
|
var DefaultFindOptions = &FindOptions{IgnorePrivate: false, DefaultRule: DefaultRule}
|
||||||
|
@ -45,7 +52,15 @@ type Rule struct {
|
||||||
// ParserOption are the options you can use to customize the way a List
|
// ParserOption are the options you can use to customize the way a List
|
||||||
// is parsed from a file or a string.
|
// is parsed from a file or a string.
|
||||||
type ParserOption struct {
|
type ParserOption struct {
|
||||||
|
// Set to false to skip the private domains when parsing.
|
||||||
|
// Default to true, which means the private domains are included.
|
||||||
PrivateDomains bool
|
PrivateDomains bool
|
||||||
|
|
||||||
|
// Set to false if the input is encoded in U-labels (Unicode)
|
||||||
|
// as opposite to A-labels.
|
||||||
|
// Default to false, which means the list is containing Unicode domains.
|
||||||
|
// This is the default because the original PSL currently contains Unicode.
|
||||||
|
ASCIIEncoded bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// FindOptions are the options you can use to customize the way a Rule
|
// FindOptions are the options you can use to customize the way a Rule
|
||||||
|
@ -119,7 +134,7 @@ func (l *List) AddRule(r *Rule) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// experimental
|
// Size returns the size of the list, which is the number of rules.
|
||||||
func (l *List) Size() int {
|
func (l *List) Size() int {
|
||||||
return len(l.rules)
|
return len(l.rules)
|
||||||
}
|
}
|
||||||
|
@ -154,7 +169,18 @@ Scanning:
|
||||||
break
|
break
|
||||||
|
|
||||||
default:
|
default:
|
||||||
rule := NewRule(line)
|
var rule *Rule
|
||||||
|
var err error
|
||||||
|
|
||||||
|
if options.ASCIIEncoded {
|
||||||
|
rule, err = NewRule(line)
|
||||||
|
} else {
|
||||||
|
rule, err = NewRuleUnicode(line)
|
||||||
|
}
|
||||||
|
if err != nil {
|
||||||
|
return []Rule{}, err
|
||||||
|
}
|
||||||
|
|
||||||
rule.Private = (section == 2)
|
rule.Private = (section == 2)
|
||||||
l.AddRule(rule)
|
l.AddRule(rule)
|
||||||
rules = append(rules, *rule)
|
rules = append(rules, *rule)
|
||||||
|
@ -207,7 +233,9 @@ func (l *List) selectRules(name string, options *FindOptions) []Rule {
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRule parses the rule content, creates and returns a Rule.
|
// NewRule parses the rule content, creates and returns a Rule.
|
||||||
func NewRule(content string) *Rule {
|
//
|
||||||
|
// The content of the rule MUST be encoded in ASCII (A-labels).
|
||||||
|
func NewRule(content string) (*Rule, error) {
|
||||||
var rule *Rule
|
var rule *Rule
|
||||||
var value string
|
var value string
|
||||||
|
|
||||||
|
@ -226,6 +254,28 @@ func NewRule(content string) *Rule {
|
||||||
value = content
|
value = content
|
||||||
rule = &Rule{Type: NormalType, Value: value, Length: len(Labels(value))}
|
rule = &Rule{Type: NormalType, Value: value, Length: len(Labels(value))}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return rule, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewRuleUnicode is like NewRule, but expects the content to be encoded in Unicode (U-labels).
|
||||||
|
func NewRuleUnicode(content string) (*Rule, error) {
|
||||||
|
var err error
|
||||||
|
|
||||||
|
content, err = idna.ToASCII(content)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return NewRule(content)
|
||||||
|
}
|
||||||
|
|
||||||
|
// MustNewRule is like NewRule, but panics if the content cannot be parsed.
|
||||||
|
func MustNewRule(content string) *Rule {
|
||||||
|
rule, err := NewRule(content)
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
return rule
|
return rule
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue