Skip to content

Commit

Permalink
fix(cruby): reset libxml2's error handler in sax and push parsers
Browse files Browse the repository at this point in the history
Note that this change regresses the behavior changed in 771164d which
we'll have to fix in an upcoming commit.

Related to #2168, #87
  • Loading branch information
flavorjones committed Jan 6, 2021
1 parent 07459fd commit 35aa88b
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions ext/nokogiri/html_sax_parser_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions ext/nokogiri/html_sax_push_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions ext/nokogiri/xml_sax_parser_context.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions ext/nokogiri/xml_sax_push_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 35aa88b

Please sign in to comment.