Skip to content

Best way to detect if input is invalid #384

Answered by tiesont
jkuek asked this question in Q&A
Discussion options

You must be logged in to vote

The RemovingTag event will be raised anytime a tag is detected which isn't allowed - you can find an example of handling that in the wiki: https://github.com/mganss/HtmlSanitizer/wiki/Examples#ex10-keep-images-audio-and-video-only-from-your-cdn

If you can handle an exception in your workflow, something like this might work:

sanitizer.RemovingTag += (sender, e) => 
{
    throw new ForbiddenTagException(e.Tag);
}

where ForbiddenTagException is a custom exception that accepts an IElement argument (assuming that you want to log what the tag was at some point).

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by jkuek
Comment options

You must be logged in to vote
1 reply
@tiesont
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants