Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML Sanitization in C++

Is there any available C++ (or maybe C) function/class/library with only purpose to sanitize a string that might contain HTML?

I find a lot of source code for sanitizing in C# or other languages more used in web application but nothing in C++.

I'll try to implement my own function if I don't find any available but I think an heavily tested solution would be far better.

edit> Some more precisions on my needs :

I'm getting text input from keyboard in my C++ application. Then I need to sanitize it before using it as a parameter in a javascript function call. That javascript run in a loaded html page that is automatically rendered (via Chromium) in a texture that I display via a library (Navi). So, the javascript function I use will simply take the given text, put P tag around the text and inject it in a div like this :

text_display.innerHTML += text_to_add;

I need to sanitize the text before sending it to the web page, be it for this function or another. It just have to be sanitized before input in Chromium.

like image 335
Klaim Avatar asked May 09 '26 03:05

Klaim


2 Answers

HTML Tidy is written in c, but there are bindings for practically every language/platform, including c++.

like image 199
Rex M Avatar answered May 10 '26 19:05

Rex M


You could use libxml2's xmlEncodeSpecialChars.

like image 20
Ben Straub Avatar answered May 10 '26 17:05

Ben Straub



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!