nh3 icon indicating copy to clipboard operation
nh3 copied to clipboard

PanicException if allowed attribute is missing

Open Alex3917 opened this issue 1 year ago • 2 comments

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()

Alex3917 avatar Jan 22 '24 12:01 Alex3917

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

triopter avatar Jan 30 '24 22:01 triopter

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.

Ozzletroll avatar Apr 19 '24 16:04 Ozzletroll