glide up
This commit is contained in:
		
							
								
								
									
										390
									
								
								vendor/golang.org/x/net/idna/idna.go
									
									
									
										generated
									
									
										vendored
									
									
								
							
							
						
						
									
										390
									
								
								vendor/golang.org/x/net/idna/idna.go
									
									
									
										generated
									
									
										vendored
									
									
								
							@@ -1,4 +1,4 @@
 | 
			
		||||
// Code generated by running "go generate" in golang.org/x/text. DO NOT EDIT.
 | 
			
		||||
// Copied from the golang.org/x/text repo; DO NOT EDIT
 | 
			
		||||
 | 
			
		||||
// Copyright 2016 The Go Authors. All rights reserved.
 | 
			
		||||
// Use of this source code is governed by a BSD-style
 | 
			
		||||
@@ -39,24 +39,27 @@ import (
 | 
			
		||||
//    error in the future.
 | 
			
		||||
// I think Option 1 is best, but it is quite opinionated.
 | 
			
		||||
 | 
			
		||||
// ToASCII is a wrapper for Punycode.ToASCII.
 | 
			
		||||
// ToASCII converts a domain or domain label to its ASCII form. For example,
 | 
			
		||||
// ToASCII("bücher.example.com") is "xn--bcher-kva.example.com", and
 | 
			
		||||
// ToASCII("golang") is "golang". If an error is encountered it will return
 | 
			
		||||
// an error and a (partially) processed result.
 | 
			
		||||
func ToASCII(s string) (string, error) {
 | 
			
		||||
	return Punycode.process(s, true)
 | 
			
		||||
	return Resolve.process(s, true)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ToUnicode is a wrapper for Punycode.ToUnicode.
 | 
			
		||||
// ToUnicode converts a domain or domain label to its Unicode form. For example,
 | 
			
		||||
// ToUnicode("xn--bcher-kva.example.com") is "bücher.example.com", and
 | 
			
		||||
// ToUnicode("golang") is "golang". If an error is encountered it will return
 | 
			
		||||
// an error and a (partially) processed result.
 | 
			
		||||
func ToUnicode(s string) (string, error) {
 | 
			
		||||
	return Punycode.process(s, false)
 | 
			
		||||
	return NonTransitional.process(s, false)
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// An Option configures a Profile at creation time.
 | 
			
		||||
type Option func(*options)
 | 
			
		||||
 | 
			
		||||
// Transitional sets a Profile to use the Transitional mapping as defined in UTS
 | 
			
		||||
// #46. This will cause, for example, "ß" to be mapped to "ss". Using the
 | 
			
		||||
// transitional mapping provides a compromise between IDNA2003 and IDNA2008
 | 
			
		||||
// compatibility. It is used by most browsers when resolving domain names. This
 | 
			
		||||
// option is only meaningful if combined with MapForLookup.
 | 
			
		||||
// Transitional sets a Profile to use the Transitional mapping as defined
 | 
			
		||||
// in UTS #46.
 | 
			
		||||
func Transitional(transitional bool) Option {
 | 
			
		||||
	return func(o *options) { o.transitional = true }
 | 
			
		||||
}
 | 
			
		||||
@@ -67,93 +70,19 @@ func VerifyDNSLength(verify bool) Option {
 | 
			
		||||
	return func(o *options) { o.verifyDNSLength = verify }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ValidateLabels sets whether to check the mandatory label validation criteria
 | 
			
		||||
// as defined in Section 5.4 of RFC 5891. This includes testing for correct use
 | 
			
		||||
// of hyphens ('-'), normalization, validity of runes, and the context rules.
 | 
			
		||||
func ValidateLabels(enable bool) Option {
 | 
			
		||||
	return func(o *options) {
 | 
			
		||||
		// Don't override existing mappings, but set one that at least checks
 | 
			
		||||
		// normalization if it is not set.
 | 
			
		||||
		if o.mapping == nil && enable {
 | 
			
		||||
			o.mapping = normalize
 | 
			
		||||
		}
 | 
			
		||||
		o.trie = trie
 | 
			
		||||
		o.validateLabels = enable
 | 
			
		||||
		o.fromPuny = validateFromPunycode
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// StrictDomainName limits the set of permissable ASCII characters to those
 | 
			
		||||
// allowed in domain names as defined in RFC 1034 (A-Z, a-z, 0-9 and the
 | 
			
		||||
// hyphen). This is set by default for MapForLookup and ValidateForRegistration.
 | 
			
		||||
//
 | 
			
		||||
// This option is useful, for instance, for browsers that allow characters
 | 
			
		||||
// outside this range, for example a '_' (U+005F LOW LINE). See
 | 
			
		||||
// http://www.rfc-editor.org/std/std3.txt for more details This option
 | 
			
		||||
// corresponds to the UseSTD3ASCIIRules option in UTS #46.
 | 
			
		||||
func StrictDomainName(use bool) Option {
 | 
			
		||||
	return func(o *options) {
 | 
			
		||||
		o.trie = trie
 | 
			
		||||
		o.useSTD3Rules = use
 | 
			
		||||
		o.fromPuny = validateFromPunycode
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// NOTE: the following options pull in tables. The tables should not be linked
 | 
			
		||||
// in as long as the options are not used.
 | 
			
		||||
 | 
			
		||||
// BidiRule enables the Bidi rule as defined in RFC 5893. Any application
 | 
			
		||||
// that relies on proper validation of labels should include this rule.
 | 
			
		||||
func BidiRule() Option {
 | 
			
		||||
	return func(o *options) { o.bidirule = bidirule.ValidString }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// ValidateForRegistration sets validation options to verify that a given IDN is
 | 
			
		||||
// properly formatted for registration as defined by Section 4 of RFC 5891.
 | 
			
		||||
func ValidateForRegistration() Option {
 | 
			
		||||
	return func(o *options) {
 | 
			
		||||
		o.mapping = validateRegistration
 | 
			
		||||
		StrictDomainName(true)(o)
 | 
			
		||||
		ValidateLabels(true)(o)
 | 
			
		||||
		VerifyDNSLength(true)(o)
 | 
			
		||||
		BidiRule()(o)
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// MapForLookup sets validation and mapping options such that a given IDN is
 | 
			
		||||
// transformed for domain name lookup according to the requirements set out in
 | 
			
		||||
// Section 5 of RFC 5891. The mappings follow the recommendations of RFC 5894,
 | 
			
		||||
// RFC 5895 and UTS 46. It does not add the Bidi Rule. Use the BidiRule option
 | 
			
		||||
// to add this check.
 | 
			
		||||
//
 | 
			
		||||
// The mappings include normalization and mapping case, width and other
 | 
			
		||||
// compatibility mappings.
 | 
			
		||||
func MapForLookup() Option {
 | 
			
		||||
	return func(o *options) {
 | 
			
		||||
		o.mapping = validateAndMap
 | 
			
		||||
		StrictDomainName(true)(o)
 | 
			
		||||
		ValidateLabels(true)(o)
 | 
			
		||||
	}
 | 
			
		||||
// IgnoreSTD3Rules sets whether ASCII characters outside the A-Z, a-z, 0-9 and
 | 
			
		||||
// the hyphen should be allowed. By default this is not allowed, but IDNA2003,
 | 
			
		||||
// and as a consequence UTS #46, allows this to be overridden to support
 | 
			
		||||
// browsers that allow characters outside this range, for example a '_' (U+005F
 | 
			
		||||
// LOW LINE). See http://www.rfc- editor.org/std/std3.txt for more details.
 | 
			
		||||
func IgnoreSTD3Rules(ignore bool) Option {
 | 
			
		||||
	return func(o *options) { o.ignoreSTD3Rules = ignore }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
type options struct {
 | 
			
		||||
	transitional    bool
 | 
			
		||||
	useSTD3Rules    bool
 | 
			
		||||
	validateLabels  bool
 | 
			
		||||
	ignoreSTD3Rules bool
 | 
			
		||||
	verifyDNSLength bool
 | 
			
		||||
 | 
			
		||||
	trie *idnaTrie
 | 
			
		||||
 | 
			
		||||
	// fromPuny calls validation rules when converting A-labels to U-labels.
 | 
			
		||||
	fromPuny func(p *Profile, s string) error
 | 
			
		||||
 | 
			
		||||
	// mapping implements a validation and mapping step as defined in RFC 5895
 | 
			
		||||
	// or UTS 46, tailored to, for example, domain registration or lookup.
 | 
			
		||||
	mapping func(p *Profile, s string) (string, error)
 | 
			
		||||
 | 
			
		||||
	// bidirule, if specified, checks whether s conforms to the Bidi Rule
 | 
			
		||||
	// defined in RFC 5893.
 | 
			
		||||
	bidirule func(s string) bool
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// A Profile defines the configuration of a IDNA mapper.
 | 
			
		||||
@@ -168,13 +97,8 @@ func apply(o *options, opts []Option) {
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// New creates a new Profile.
 | 
			
		||||
//
 | 
			
		||||
// With no options, the returned Profile is the most permissive and equals the
 | 
			
		||||
// Punycode Profile. Options can be passed to further restrict the Profile. The
 | 
			
		||||
// MapForLookup and ValidateForRegistration options set a collection of options,
 | 
			
		||||
// for lookup and registration purposes respectively, which can be tailored by
 | 
			
		||||
// adding more fine-grained options, where later options override earlier
 | 
			
		||||
// options.
 | 
			
		||||
// With no options, the returned profile is the non-transitional profile as
 | 
			
		||||
// defined in UTS #46.
 | 
			
		||||
func New(o ...Option) *Profile {
 | 
			
		||||
	p := &Profile{}
 | 
			
		||||
	apply(&p.options, o)
 | 
			
		||||
@@ -208,67 +132,33 @@ func (p *Profile) String() string {
 | 
			
		||||
	} else {
 | 
			
		||||
		s = "NonTransitional"
 | 
			
		||||
	}
 | 
			
		||||
	if p.useSTD3Rules {
 | 
			
		||||
		s += ":UseSTD3Rules"
 | 
			
		||||
	}
 | 
			
		||||
	if p.validateLabels {
 | 
			
		||||
		s += ":ValidateLabels"
 | 
			
		||||
	}
 | 
			
		||||
	if p.verifyDNSLength {
 | 
			
		||||
		s += ":VerifyDNSLength"
 | 
			
		||||
	if p.ignoreSTD3Rules {
 | 
			
		||||
		s += ":NoSTD3Rules"
 | 
			
		||||
	}
 | 
			
		||||
	return s
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
var (
 | 
			
		||||
	// Punycode is a Profile that does raw punycode processing with a minimum
 | 
			
		||||
	// of validation.
 | 
			
		||||
	Punycode *Profile = punycode
 | 
			
		||||
 | 
			
		||||
	// Lookup is the recommended profile for looking up domain names, according
 | 
			
		||||
	// to Section 5 of RFC 5891. The exact configuration of this profile may
 | 
			
		||||
	// change over time.
 | 
			
		||||
	Lookup *Profile = lookup
 | 
			
		||||
	// Resolve is the recommended profile for resolving domain names.
 | 
			
		||||
	// The configuration of this profile may change over time.
 | 
			
		||||
	Resolve = resolve
 | 
			
		||||
 | 
			
		||||
	// Display is the recommended profile for displaying domain names.
 | 
			
		||||
	// The configuration of this profile may change over time.
 | 
			
		||||
	Display *Profile = display
 | 
			
		||||
	Display = display
 | 
			
		||||
 | 
			
		||||
	// Registration is the recommended profile for checking whether a given
 | 
			
		||||
	// IDN is valid for registration, according to Section 4 of RFC 5891.
 | 
			
		||||
	Registration *Profile = registration
 | 
			
		||||
	// NonTransitional defines a profile that implements the Transitional
 | 
			
		||||
	// mapping as defined in UTS #46 with no additional constraints.
 | 
			
		||||
	NonTransitional = nonTransitional
 | 
			
		||||
 | 
			
		||||
	punycode = &Profile{}
 | 
			
		||||
	lookup   = &Profile{options{
 | 
			
		||||
		transitional:   true,
 | 
			
		||||
		useSTD3Rules:   true,
 | 
			
		||||
		validateLabels: true,
 | 
			
		||||
		trie:           trie,
 | 
			
		||||
		fromPuny:       validateFromPunycode,
 | 
			
		||||
		mapping:        validateAndMap,
 | 
			
		||||
		bidirule:       bidirule.ValidString,
 | 
			
		||||
	}}
 | 
			
		||||
	display = &Profile{options{
 | 
			
		||||
		useSTD3Rules:   true,
 | 
			
		||||
		validateLabels: true,
 | 
			
		||||
		trie:           trie,
 | 
			
		||||
		fromPuny:       validateFromPunycode,
 | 
			
		||||
		mapping:        validateAndMap,
 | 
			
		||||
		bidirule:       bidirule.ValidString,
 | 
			
		||||
	}}
 | 
			
		||||
	registration = &Profile{options{
 | 
			
		||||
		useSTD3Rules:    true,
 | 
			
		||||
		validateLabels:  true,
 | 
			
		||||
		verifyDNSLength: true,
 | 
			
		||||
		trie:            trie,
 | 
			
		||||
		fromPuny:        validateFromPunycode,
 | 
			
		||||
		mapping:         validateRegistration,
 | 
			
		||||
		bidirule:        bidirule.ValidString,
 | 
			
		||||
	}}
 | 
			
		||||
	resolve         = &Profile{options{transitional: true}}
 | 
			
		||||
	display         = &Profile{}
 | 
			
		||||
	nonTransitional = &Profile{}
 | 
			
		||||
 | 
			
		||||
	// TODO: profiles
 | 
			
		||||
	// Register: recommended for approving domain names: don't do any mappings
 | 
			
		||||
	// but rather reject on invalid input. Bundle or block deviation characters.
 | 
			
		||||
	// V2008: strict IDNA2008
 | 
			
		||||
	// Register: recommended for approving domain names: nontransitional, but
 | 
			
		||||
	// bundle or block deviation characters.
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
type labelError struct{ label, code_ string }
 | 
			
		||||
@@ -288,117 +178,12 @@ func (e runeError) Error() string {
 | 
			
		||||
// process implements the algorithm described in section 4 of UTS #46,
 | 
			
		||||
// see http://www.unicode.org/reports/tr46.
 | 
			
		||||
func (p *Profile) process(s string, toASCII bool) (string, error) {
 | 
			
		||||
	var err error
 | 
			
		||||
	if p.mapping != nil {
 | 
			
		||||
		s, err = p.mapping(p, s)
 | 
			
		||||
	}
 | 
			
		||||
	// Remove leading empty labels.
 | 
			
		||||
	for ; len(s) > 0 && s[0] == '.'; s = s[1:] {
 | 
			
		||||
	}
 | 
			
		||||
	// It seems like we should only create this error on ToASCII, but the
 | 
			
		||||
	// UTS 46 conformance tests suggests we should always check this.
 | 
			
		||||
	if err == nil && p.verifyDNSLength && s == "" {
 | 
			
		||||
		err = &labelError{s, "A4"}
 | 
			
		||||
	}
 | 
			
		||||
	labels := labelIter{orig: s}
 | 
			
		||||
	for ; !labels.done(); labels.next() {
 | 
			
		||||
		label := labels.label()
 | 
			
		||||
		if label == "" {
 | 
			
		||||
			// Empty labels are not okay. The label iterator skips the last
 | 
			
		||||
			// label if it is empty.
 | 
			
		||||
			if err == nil && p.verifyDNSLength {
 | 
			
		||||
				err = &labelError{s, "A4"}
 | 
			
		||||
			}
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		if strings.HasPrefix(label, acePrefix) {
 | 
			
		||||
			u, err2 := decode(label[len(acePrefix):])
 | 
			
		||||
			if err2 != nil {
 | 
			
		||||
				if err == nil {
 | 
			
		||||
					err = err2
 | 
			
		||||
				}
 | 
			
		||||
				// Spec says keep the old label.
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
			labels.set(u)
 | 
			
		||||
			if err == nil && p.validateLabels {
 | 
			
		||||
				err = p.fromPuny(p, u)
 | 
			
		||||
			}
 | 
			
		||||
			if err == nil {
 | 
			
		||||
				// This should be called on NonTransitional, according to the
 | 
			
		||||
				// spec, but that currently does not have any effect. Use the
 | 
			
		||||
				// original profile to preserve options.
 | 
			
		||||
				err = p.validateLabel(u)
 | 
			
		||||
			}
 | 
			
		||||
		} else if err == nil {
 | 
			
		||||
			err = p.validateLabel(label)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if toASCII {
 | 
			
		||||
		for labels.reset(); !labels.done(); labels.next() {
 | 
			
		||||
			label := labels.label()
 | 
			
		||||
			if !ascii(label) {
 | 
			
		||||
				a, err2 := encode(acePrefix, label)
 | 
			
		||||
				if err == nil {
 | 
			
		||||
					err = err2
 | 
			
		||||
				}
 | 
			
		||||
				label = a
 | 
			
		||||
				labels.set(a)
 | 
			
		||||
			}
 | 
			
		||||
			n := len(label)
 | 
			
		||||
			if p.verifyDNSLength && err == nil && (n == 0 || n > 63) {
 | 
			
		||||
				err = &labelError{label, "A4"}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	s = labels.result()
 | 
			
		||||
	if toASCII && p.verifyDNSLength && err == nil {
 | 
			
		||||
		// Compute the length of the domain name minus the root label and its dot.
 | 
			
		||||
		n := len(s)
 | 
			
		||||
		if n > 0 && s[n-1] == '.' {
 | 
			
		||||
			n--
 | 
			
		||||
		}
 | 
			
		||||
		if len(s) < 1 || n > 253 {
 | 
			
		||||
			err = &labelError{s, "A4"}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return s, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func normalize(p *Profile, s string) (string, error) {
 | 
			
		||||
	return norm.NFC.String(s), nil
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func validateRegistration(p *Profile, s string) (string, error) {
 | 
			
		||||
	if !norm.NFC.IsNormalString(s) {
 | 
			
		||||
		return s, &labelError{s, "V1"}
 | 
			
		||||
	}
 | 
			
		||||
	var err error
 | 
			
		||||
	for i := 0; i < len(s); {
 | 
			
		||||
		v, sz := trie.lookupString(s[i:])
 | 
			
		||||
		i += sz
 | 
			
		||||
		// Copy bytes not copied so far.
 | 
			
		||||
		switch p.simplify(info(v).category()) {
 | 
			
		||||
		// TODO: handle the NV8 defined in the Unicode idna data set to allow
 | 
			
		||||
		// for strict conformance to IDNA2008.
 | 
			
		||||
		case valid, deviation:
 | 
			
		||||
		case disallowed, mapped, unknown, ignored:
 | 
			
		||||
			if err == nil {
 | 
			
		||||
				r, _ := utf8.DecodeRuneInString(s[i:])
 | 
			
		||||
				err = runeError(r)
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return s, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func validateAndMap(p *Profile, s string) (string, error) {
 | 
			
		||||
	var (
 | 
			
		||||
		err error
 | 
			
		||||
		b   []byte
 | 
			
		||||
		k   int
 | 
			
		||||
		b    []byte
 | 
			
		||||
		err  error
 | 
			
		||||
		k, i int
 | 
			
		||||
	)
 | 
			
		||||
	for i := 0; i < len(s); {
 | 
			
		||||
	for i < len(s) {
 | 
			
		||||
		v, sz := trie.lookupString(s[i:])
 | 
			
		||||
		start := i
 | 
			
		||||
		i += sz
 | 
			
		||||
@@ -435,6 +220,71 @@ func validateAndMap(p *Profile, s string) (string, error) {
 | 
			
		||||
		// TODO: the punycode converters require strings as input.
 | 
			
		||||
		s = string(b)
 | 
			
		||||
	}
 | 
			
		||||
	// Remove leading empty labels
 | 
			
		||||
	for ; len(s) > 0 && s[0] == '.'; s = s[1:] {
 | 
			
		||||
	}
 | 
			
		||||
	if s == "" {
 | 
			
		||||
		return "", &labelError{s, "A4"}
 | 
			
		||||
	}
 | 
			
		||||
	labels := labelIter{orig: s}
 | 
			
		||||
	for ; !labels.done(); labels.next() {
 | 
			
		||||
		label := labels.label()
 | 
			
		||||
		if label == "" {
 | 
			
		||||
			// Empty labels are not okay. The label iterator skips the last
 | 
			
		||||
			// label if it is empty.
 | 
			
		||||
			if err == nil {
 | 
			
		||||
				err = &labelError{s, "A4"}
 | 
			
		||||
			}
 | 
			
		||||
			continue
 | 
			
		||||
		}
 | 
			
		||||
		if strings.HasPrefix(label, acePrefix) {
 | 
			
		||||
			u, err2 := decode(label[len(acePrefix):])
 | 
			
		||||
			if err2 != nil {
 | 
			
		||||
				if err == nil {
 | 
			
		||||
					err = err2
 | 
			
		||||
				}
 | 
			
		||||
				// Spec says keep the old label.
 | 
			
		||||
				continue
 | 
			
		||||
			}
 | 
			
		||||
			labels.set(u)
 | 
			
		||||
			if err == nil {
 | 
			
		||||
				err = p.validateFromPunycode(u)
 | 
			
		||||
			}
 | 
			
		||||
			if err == nil {
 | 
			
		||||
				err = NonTransitional.validate(u)
 | 
			
		||||
			}
 | 
			
		||||
		} else if err == nil {
 | 
			
		||||
			err = p.validate(label)
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	if toASCII {
 | 
			
		||||
		for labels.reset(); !labels.done(); labels.next() {
 | 
			
		||||
			label := labels.label()
 | 
			
		||||
			if !ascii(label) {
 | 
			
		||||
				a, err2 := encode(acePrefix, label)
 | 
			
		||||
				if err == nil {
 | 
			
		||||
					err = err2
 | 
			
		||||
				}
 | 
			
		||||
				label = a
 | 
			
		||||
				labels.set(a)
 | 
			
		||||
			}
 | 
			
		||||
			n := len(label)
 | 
			
		||||
			if p.verifyDNSLength && err == nil && (n == 0 || n > 63) {
 | 
			
		||||
				err = &labelError{label, "A4"}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	s = labels.result()
 | 
			
		||||
	if toASCII && p.verifyDNSLength && err == nil {
 | 
			
		||||
		// Compute the length of the domain name minus the root label and its dot.
 | 
			
		||||
		n := len(s)
 | 
			
		||||
		if n > 0 && s[n-1] == '.' {
 | 
			
		||||
			n--
 | 
			
		||||
		}
 | 
			
		||||
		if len(s) < 1 || n > 253 {
 | 
			
		||||
			err = &labelError{s, "A4"}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	return s, err
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -504,13 +354,13 @@ const acePrefix = "xn--"
 | 
			
		||||
func (p *Profile) simplify(cat category) category {
 | 
			
		||||
	switch cat {
 | 
			
		||||
	case disallowedSTD3Mapped:
 | 
			
		||||
		if p.useSTD3Rules {
 | 
			
		||||
		if !p.ignoreSTD3Rules {
 | 
			
		||||
			cat = disallowed
 | 
			
		||||
		} else {
 | 
			
		||||
			cat = mapped
 | 
			
		||||
		}
 | 
			
		||||
	case disallowedSTD3Valid:
 | 
			
		||||
		if p.useSTD3Rules {
 | 
			
		||||
		if !p.ignoreSTD3Rules {
 | 
			
		||||
			cat = disallowed
 | 
			
		||||
		} else {
 | 
			
		||||
			cat = valid
 | 
			
		||||
@@ -526,7 +376,7 @@ func (p *Profile) simplify(cat category) category {
 | 
			
		||||
	return cat
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
func validateFromPunycode(p *Profile, s string) error {
 | 
			
		||||
func (p *Profile) validateFromPunycode(s string) error {
 | 
			
		||||
	if !norm.NFC.IsNormalString(s) {
 | 
			
		||||
		return &labelError{s, "V1"}
 | 
			
		||||
	}
 | 
			
		||||
@@ -602,22 +452,9 @@ var joinStates = [][numJoinTypes]joinState{
 | 
			
		||||
	},
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
// validateLabel validates the criteria from Section 4.1. Item 1, 4, and 6 are
 | 
			
		||||
// validate validates the criteria from Section 4.1. Item 1, 4, and 6 are
 | 
			
		||||
// already implicitly satisfied by the overall implementation.
 | 
			
		||||
func (p *Profile) validateLabel(s string) error {
 | 
			
		||||
	if s == "" {
 | 
			
		||||
		if p.verifyDNSLength {
 | 
			
		||||
			return &labelError{s, "A4"}
 | 
			
		||||
		}
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	if p.bidirule != nil && !p.bidirule(s) {
 | 
			
		||||
		return &labelError{s, "B"}
 | 
			
		||||
	}
 | 
			
		||||
	if !p.validateLabels {
 | 
			
		||||
		return nil
 | 
			
		||||
	}
 | 
			
		||||
	trie := p.trie // p.validateLabels is only set if trie is set.
 | 
			
		||||
func (p *Profile) validate(s string) error {
 | 
			
		||||
	if len(s) > 4 && s[2] == '-' && s[3] == '-' {
 | 
			
		||||
		return &labelError{s, "V2"}
 | 
			
		||||
	}
 | 
			
		||||
@@ -630,6 +467,9 @@ func (p *Profile) validateLabel(s string) error {
 | 
			
		||||
	if x.isModifier() {
 | 
			
		||||
		return &labelError{s, "V5"}
 | 
			
		||||
	}
 | 
			
		||||
	if !bidirule.ValidString(s) {
 | 
			
		||||
		return &labelError{s, "B"}
 | 
			
		||||
	}
 | 
			
		||||
	// Quickly return in the absence of zero-width (non) joiners.
 | 
			
		||||
	if strings.Index(s, zwj) == -1 && strings.Index(s, zwnj) == -1 {
 | 
			
		||||
		return nil
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user