void EncodeRefs(WString& text, WFlags<RefEncoderOption> options) { if (text.empty()) return; std::string result = "<span>" + text.toUTF8() + "</span>"; char *ctext = const_cast<char *>(result.c_str()); // Shhht it's okay ! WApplication *app = WApplication::instance(); try { xml_document<> doc; doc.parse<parse_comment_nodes | parse_validate_closing_tags | parse_validate_utf8 | parse_xhtml_entity_translation>(ctext); EncodeRefs(doc.first_node(), app, options); WStringStream out; print(out.back_inserter(), *doc.first_node(), print_no_indenting); result = out.str(); } catch (parse_error& e) { LOG_ERROR("Error reading XHTML string: " << e.what()); return; } if (result.length() < 13) result.clear(); else result = result.substr(6, result.length() - 13); text = WString::fromUTF8(result); }
bool XSSFilterRemoveScript(WString& text) { if (text.empty()) return true; std::string result = "<span>" + text.toUTF8() + "</span>"; char *ctext = const_cast<char *>(result.c_str()); // Shhht it's okay ! try { xml_document<> doc; doc.parse<parse_comment_nodes | parse_validate_closing_tags | parse_validate_utf8 | parse_xhtml_entity_translation>(ctext); XSSSanitize(doc.first_node()); WStringStream out; print(out.back_inserter(), *doc.first_node(), print_no_indenting); result = out.str(); } catch (parse_error& e) { LOG_ERROR("Error reading XHTML string: " << e.what()); return false; } if (result.length() < 13) result.clear(); else result = result.substr(6, result.length() - 13); text = WString::fromUTF8(result); return true; }