rust-ammonia / ammonia

Repair and secure untrusted HTML
Apache License 2.0
524 stars 43 forks source link

Improve error message when clean_content_tags and tags overlap #200

Closed nijel closed 4 months ago

nijel commented 4 months ago

Is your feature request related to a problem? Please describe.

When tags and clean_content_tags overlap, the library fails with assertion failed: !self.tags.contains(tag_name) instead of giving an useful error message.

I've ran into this via nh3, but I think it could be useful to address in amonia.

Reproducer:

>>> nh3.clean('test', tags={'style'})
thread 'python' panicked at /root/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ammonia-4.0.0/src/lib.rs:1791:13:
assertion failed: !self.tags.contains(tag_name)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
pyo3_runtime.PanicException: assertion failed: !self.tags.contains(tag_name)

Describe the solution you'd like Get an error message that clean_content_tags and tags should not overlap.

Describe alternatives you've considered I've figured out what is wrong after reading the code, but that it not really a friendly way to understand what went wrong.