Beispiel #1
0
// NormalizeURL returns the normalized string.
// It takes a parsed URL object as input, as well as the normalization flags.
func NormalizeURL(u *url.URL, f NormalizationFlags) string {
	for _, k := range flagsOrder {
		if f&k == k {
			flags[k](u)
		}
	}
	return urlesc.Escape(u)
}
Beispiel #2
0
func normalizeLink(rawurl string) string {
	parsed, err := url.Parse(rawurl)
	if err != nil {
		return ""
	}

	return urlesc.Escape(parsed)
}
Beispiel #3
0
func NormalizeURLWithCustomizer(u *url.URL, f NormalizationFlags, c Customizer) string {
	if c != nil {
		// give the Customizer a chance to adjust the flags
		f = c.AdjustFlags(f)
	}
	for _, k := range flagsOrder {
		if k == flagEditQuery {
			// we only need to edit the QP if we are asked to via a flag or editing fn
			shouldSort := f&FlagSortQuery == FlagSortQuery
			if shouldSort || c != nil {
				editQuery(u, shouldSort, c)
			}
		} else if f&k == k {
			flags[k](u)
		}
	}
	return urlesc.Escape(u)
}