From 35aa88b75e7d8436217471ef6ff58f814466b26e Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Tue, 5 Jan 2021 17:25:00 -0500 Subject: [PATCH] fix(cruby): reset libxml2's error handler in sax and push parsers Note that this change regresses the behavior changed in 771164d which we'll have to fix in an upcoming commit. Related to #2168, #87 --- ext/nokogiri/html_sax_parser_context.c | 2 ++ ext/nokogiri/html_sax_push_parser.c | 2 ++ ext/nokogiri/xml_sax_parser_context.c | 2 ++ ext/nokogiri/xml_sax_push_parser.c | 2 ++ 4 files changed, 8 insertions(+) diff --git a/ext/nokogiri/html_sax_parser_context.c b/ext/nokogiri/html_sax_parser_context.c index 9f41b51adf..7f1379abf2 100644 --- a/ext/nokogiri/html_sax_parser_context.c +++ b/ext/nokogiri/html_sax_parser_context.c @@ -92,6 +92,8 @@ parse_with(VALUE self, VALUE sax_handler) ctxt->sax = sax; ctxt->userData = (void *)NOKOGIRI_SAX_TUPLE_NEW(ctxt, sax_handler); + xmlSetStructuredErrorFunc(NULL, NULL); + rb_ensure(parse_doc, (VALUE)ctxt, parse_doc_finalize, (VALUE)ctxt); return self; diff --git a/ext/nokogiri/html_sax_push_parser.c b/ext/nokogiri/html_sax_push_parser.c index 2df4532f10..3a739ae1d2 100644 --- a/ext/nokogiri/html_sax_push_parser.c +++ b/ext/nokogiri/html_sax_push_parser.c @@ -20,6 +20,8 @@ static VALUE native_write(VALUE self, VALUE _chunk, VALUE _last_chunk) size = (int)RSTRING_LEN(_chunk); } + xmlSetStructuredErrorFunc(NULL, NULL); + if(htmlParseChunk(ctx, chunk, size, Qtrue == _last_chunk ? 1 : 0)) { if (!(ctx->options & XML_PARSE_RECOVER)) { xmlErrorPtr e = xmlCtxtGetLastError(ctx); diff --git a/ext/nokogiri/xml_sax_parser_context.c b/ext/nokogiri/xml_sax_parser_context.c index 19c96c69c1..370d7b9fc3 100644 --- a/ext/nokogiri/xml_sax_parser_context.c +++ b/ext/nokogiri/xml_sax_parser_context.c @@ -120,6 +120,8 @@ parse_with(VALUE self, VALUE sax_handler) ctxt->sax = sax; ctxt->userData = (void *)NOKOGIRI_SAX_TUPLE_NEW(ctxt, sax_handler); + xmlSetStructuredErrorFunc(NULL, NULL); + rb_ensure(parse_doc, (VALUE)ctxt, parse_doc_finalize, (VALUE)ctxt); return Qnil; diff --git a/ext/nokogiri/xml_sax_push_parser.c b/ext/nokogiri/xml_sax_push_parser.c index dac0a24db5..9daa22767d 100644 --- a/ext/nokogiri/xml_sax_push_parser.c +++ b/ext/nokogiri/xml_sax_push_parser.c @@ -35,6 +35,8 @@ static VALUE native_write(VALUE self, VALUE _chunk, VALUE _last_chunk) size = (int)RSTRING_LEN(_chunk); } + xmlSetStructuredErrorFunc(NULL, NULL); + if (xmlParseChunk(ctx, chunk, size, Qtrue == _last_chunk ? 1 : 0)) { if (!(ctx->options & XML_PARSE_RECOVER)) { xmlErrorPtr e = xmlCtxtGetLastError(ctx);