Skip to content

Commit

Permalink
fix(jruby): call Document#initialize when creating via .parse
Browse files Browse the repository at this point in the history
This was noticed while debugging some Loofah behavior that relied on
overriding `#initialize` to decorate nodes.

Related to flavorjones/loofah#88
  • Loading branch information
flavorjones committed Jan 17, 2021
1 parent 76017be commit e5646e8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ext/java/nokogiri/internals/HtmlDomParserContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
import org.jruby.Ruby;
import org.jruby.RubyClass;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.builtin.IRubyObject;
import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
Expand Down Expand Up @@ -133,6 +134,8 @@ public XmlDocument parse(ThreadContext context, RubyClass klass, IRubyObject url
protected XmlDocument wrapDocument(ThreadContext context, RubyClass klass, Document document) {
HtmlDocument htmlDocument = new HtmlDocument(context.runtime, klass, document);
htmlDocument.setDocumentNode(context.runtime, document);
Helpers.invoke(context, htmlDocument, "initialize");

if (ruby_encoding.isNil()) {
// ruby_encoding might have detected by HtmlDocument::EncodingReader
if (detected_encoding != null && !detected_encoding.isNil()) {
Expand Down
2 changes: 2 additions & 0 deletions ext/java/nokogiri/internals/XmlDomParserContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.jruby.RubyFixnum;
import org.jruby.exceptions.RaiseException;
import org.jruby.runtime.ThreadContext;
import org.jruby.runtime.Helpers;
import org.jruby.runtime.builtin.IRubyObject;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
Expand Down Expand Up @@ -213,6 +214,7 @@ private XmlDocument getInterruptedOrNewXmlDocument(ThreadContext context, RubyCl
*/
protected XmlDocument wrapDocument(ThreadContext context, RubyClass klass, Document doc) {
XmlDocument xmlDocument = new XmlDocument(context.runtime, klass, doc);
Helpers.invoke(context, xmlDocument, "initialize");
xmlDocument.setEncoding(ruby_encoding);

if (options.dtdLoad) {
Expand Down

0 comments on commit e5646e8

Please sign in to comment.