Libxml htmlParseDocument ignores htmlParseOption flags

Looking for someone who uses libxml through a different environment than the one packaged with PHP, to confirm that the HTML_PARSE_NOWARNING flag is ignored. Alerts are still generated.

Source code from PHP implementing libxml in C:

//one of these options is 64 or HTML_PARSE_NOWARNING htmlCtxtUseOptions(ctxt, (int)options); ctxt->vctxt.error = php_libxml_ctx_error; ctxt->vctxt.warning = php_libxml_ctx_warning; if (ctxt->sax != NULL) { ctxt->sax->error = php_libxml_ctx_error; ctxt->sax->warning = php_libxml_ctx_warning; } htmlParseDocument(ctxt); //this still produces warnings 
+1
php libxml2
Jan 25 '17 at 20:05
source share
1 answer

libxml2 does not ignore the HTML_PARSE_NOWARNING flag. Calling htmlCtxtUseOptions with HTML_PARSE_NOWARNING causes alert handlers to be unregistered (set to NULL). But the PHP code then proceeds to install its own handlers unconditionally, making the flag useless. The PHP code must either add validation in order to install handlers:

 htmlCtxtUseOptions(ctxt, (int)options); if (!(options & HTML_PARSE_NOERROR)) { ctxt->vctxt.error = php_libxml_ctx_error; if (ctxt->sax != NULL) ctxt->sax->error = php_libxml_ctx_error; } if (!(options & HTML_PARSE_NOWARNING)) { ctxt->vctxt.warning = php_libxml_ctx_warning; if (ctxt->sax != NULL) ctxt->sax->warning = php_libxml_ctx_warning; } htmlParseDocument(ctxt); 

Or call htmlCtxtUseOptions after setting the handlers:

 ctxt->vctxt.error = php_libxml_ctx_error; ctxt->vctxt.warning = php_libxml_ctx_warning; if (ctxt->sax != NULL) { ctxt->sax->error = php_libxml_ctx_error; ctxt->sax->warning = php_libxml_ctx_warning; } htmlCtxtUseOptions(ctxt, (int)options); htmlParseDocument(ctxt); 
+2
Jan 26 '17 at 14:37
source share



All Articles