@@ -117,6 +117,10 @@ type Policy struct {
117117 // returning true are allowed.
118118 allowURLSchemes map [string ][]urlPolicy
119119
120+ // These regexps are used to match allowed URL schemes, for example
121+ // if one would want to allow all URL schemes, they would add `.+`
122+ allowURLSchemeRegexps []* regexp.Regexp
123+
120124 // If an element has had all attributes removed as a result of a policy
121125 // being applied, then the element would be removed from the output.
122126 //
@@ -221,6 +225,7 @@ func (p *Policy) init() {
221225 p .elsMatchingAndStyles = make (map [* regexp.Regexp ]map [string ][]stylePolicy )
222226 p .globalStyles = make (map [string ][]stylePolicy )
223227 p .allowURLSchemes = make (map [string ][]urlPolicy )
228+ p .allowURLSchemeRegexps = make ([]* regexp.Regexp , 0 )
224229 p .setOfElementsAllowedWithoutAttrs = make (map [string ]struct {})
225230 p .setOfElementsToSkipContent = make (map [string ]struct {})
226231 p .initialized = true
@@ -563,6 +568,13 @@ func (p *Policy) AllowElementsMatching(regex *regexp.Regexp) *Policy {
563568 return p
564569}
565570
571+ // AllowURLSchemesMatching will append URL schemes to the allowlist if they
572+ // match a regexp.
573+ func (p * Policy ) AllowURLSchemesMatching (r * regexp.Regexp ) * Policy {
574+ p .allowURLSchemeRegexps = append (p .allowURLSchemeRegexps , r )
575+ return p
576+ }
577+
566578// RequireNoFollowOnLinks will result in all a, area, link tags having a
567579// rel="nofollow"added to them if one does not already exist
568580//
0 commit comments