Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AllowElements regex support #92

Merged
merged 6 commits into from Nov 19, 2019
Merged

AllowElements regex support #92

merged 6 commits into from Nov 19, 2019

Conversation

theflyingcodr
Copy link
Contributor

Overview

This closes #91

It adds 3 new public methods for allowing elements to be allowed using a regex pattern, they are:

policy.AllowElementsMatching(regexp)
policy.AllowAttrs("span").OnElementsMatching(regexp)
policy.AllowStyles("color","mystyle").OnElementsMatching(regexp)

This means all elements that match the regular expression provided, will be affected by the policy being built. This allows a common prefix for example to be used for custom elements and have them all be included in the sanitized output, along with any custom attrs or styles as we can do now on explicitly allowed elements using AllowElements(...)

Rules

Some rules have been implemented, would be good to get feedback:

  1. If an element has been explicitly added via AllowElements those rules override any regex rules, the regex rules are simply ignored
  2. Don't add multiple regex patterns that overlap, as order of execution is not guaranteed and another patterns rules could end up being matched instead of your intended. For example, rules added like AllowElementsMatching(regexp.MustCompile('^my-element-')) and AllowElementsMatching(regexp.MustCompile('^my-element-other')) would not be recommended as both will get matched and we won't know reliably which rule to use.

@shaydoc
Copy link

shaydoc commented Oct 14, 2019

This will be so useful

@shaydoc
Copy link

shaydoc commented Nov 19, 2019

@buro any updates on merging this PR?

@buro9 buro9 merged commit 0a75d76 into microcosm-cc:master Nov 19, 2019
@buro9
Copy link
Member

buro9 commented Nov 19, 2019

apologies for the delay... personal life is hard, I'm mostly offline atm

@theflyingcodr
Copy link
Contributor Author

Thanks @buro9 👍

@theflyingcodr theflyingcodr deleted the element_regex branch November 19, 2019 13:16
@shaydoc
Copy link

shaydoc commented Nov 19, 2019

Thanks for merging @buro sorry to hear things are hard, hope your situation improves soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

How to allow custom elements using a regex
3 participants