From d2a79473de1a891cdda27d2dfbefccb10297fbb7 Mon Sep 17 00:00:00 2001 From: Jack McCracken Date: Mon, 11 Dec 2017 01:11:29 -0500 Subject: [PATCH] Fix JRuby extension --- ext/java/nokogiri/XmlDocumentFragment.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/ext/java/nokogiri/XmlDocumentFragment.java b/ext/java/nokogiri/XmlDocumentFragment.java index 7912303561..afb1bb1101 100644 --- a/ext/java/nokogiri/XmlDocumentFragment.java +++ b/ext/java/nokogiri/XmlDocumentFragment.java @@ -17,10 +17,10 @@ * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: - * + * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. - * + * * THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. @@ -52,6 +52,7 @@ import org.jruby.anno.JRubyMethod; import org.jruby.javasupport.util.RuntimeHelpers; import org.jruby.runtime.ThreadContext; +import org.jruby.runtime.Block; import org.jruby.runtime.builtin.IRubyObject; import org.jruby.util.ByteList; import org.w3c.dom.Attr; @@ -59,7 +60,7 @@ /** * Class for Nokogiri::XML::DocumentFragment - * + * * @author sergio * @author Yoko Harada */ @@ -75,9 +76,9 @@ public XmlDocumentFragment(Ruby ruby, RubyClass klazz) { super(ruby, klazz); } - @JRubyMethod(name="new", meta = true, required=1, optional=2) - public static IRubyObject rbNew(ThreadContext context, IRubyObject cls, IRubyObject[] args) { - + @JRubyMethod(name="new", meta = true, required=1, optional=3) + public static IRubyObject rbNew(ThreadContext context, IRubyObject cls, IRubyObject[] args, Block block) { + if(args.length < 1) { throw context.getRuntime().newArgumentError(args.length, 1); } @@ -87,7 +88,7 @@ public static IRubyObject rbNew(ThreadContext context, IRubyObject cls, IRubyObj } XmlDocument doc = (XmlDocument) args[0]; - + // make wellformed fragment, ignore invalid namespace, or add appropriate namespace to parse if (args.length > 1 && args[1] instanceof RubyString) { if (XmlDocumentFragment.isTag((RubyString)args[1])) { @@ -159,10 +160,10 @@ private static String addNamespaceDeclIfNeeded(XmlDocument doc, String tags) { tags = tags.replace(e.getKey(), e.getValue()); } } - + return tags; } - + private static CharSequence getNamespaceDecl(final String prefix, NamedNodeMap nodeMap) { for (int i=0; i < nodeMap.getLength(); i++) { Attr attr = (Attr) nodeMap.item(i);