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

Can't allow <picture> and <source> #161

Closed
felixfbecker opened this issue Jan 28, 2023 · 1 comment
Closed

Can't allow <picture> and <source> #161

felixfbecker opened this issue Jan 28, 2023 · 1 comment

Comments

@felixfbecker
Copy link

I'm trying to allow the <picture> and <source> elements in a UGCPolicy using this code:

p = bluemonday.UGCPolicy()
p.AllowElements("picture", "source")
p.AllowAttrs("srcset", "src", "type", "media").OnElements("source")
p.Sanitize("<picture><source src=\"b.jpg\" media=\"(prefers-color-scheme: dark)\"></source><img src=\"a.jpg\"></picture>")

But no matter what I do, it seems <picture> element is always stripped in the output:

<source src="b.jpg"></source><img src="a.jpg">

The use case for this is allowing to provide alternative versions of an image – different resolutions or different dark/light theme version. GitHub supports this for example in their Markdown: https://docs.github.com/en/get-started/writing-on-github/getting-started-with-writing-and-formatting-on-github/basic-writing-and-formatting-syntax#specifying-the-theme-an-image-is-shown-to

Am I doing something wrong?

@buro9 buro9 closed this as completed in ef72ac8 Jan 28, 2023
buro9 added a commit that referenced this issue Jan 28, 2023
Add picture to allowlist of elements that do not need attributes to resolve #161
@buro9
Copy link
Member

buro9 commented Jan 28, 2023

Thanks for reporting.

The picture element is one of the HTML elements that is permitted even when there are no attributes. However this was not on the allowlist for that, so I've updated that. If you run the latest version it should now work for you.

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

No branches or pull requests

2 participants