messense / nh3

Python binding to Ammonia HTML sanitizer Rust crate
https://nh3.readthedocs.io
MIT License
260 stars 8 forks source link

PanicException if allowed attribute is missing #36

Open Alex3917 opened 9 months ago

Alex3917 commented 9 months ago
html = "<a href='http://www.google.com'>google.com</a>"
nh3.clean(html, tags={'a'}, attributes={'a': {'href', 'rel'}})
pyo3_runtime.PanicException: assertion failed: self.tag_attributes.get("a").and_then(|a| a.get("rel")).is_none()
triopter commented 9 months ago

I'm also encountering this error, which makes it pretty difficult to use the module.

Ozzletroll commented 7 months ago

I encountered this exact issue when replacing Bleach with nh3, and I had to remove "rel" from the attributes dict to avoid the error. Taking a look at the docs, I found:

link_rel (str) –

Configures a rel attribute that will be added on links, defaults to noopener noreferrer. To turn on rel-insertion, pass a space-separated list. If rel is in the generic or tag attributes, this must be set to None.

Hope this helps.