Skip to content

Commit

Permalink
Fix JRuby extension
Browse files Browse the repository at this point in the history
  • Loading branch information
JackMc committed Dec 11, 2017
1 parent 1dd962b commit 4ba8b4a
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions ext/java/nokogiri/XmlDocumentFragment.java
Expand Up @@ -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.
Expand Down Expand Up @@ -52,14 +52,15 @@
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;
import org.w3c.dom.NamedNodeMap;

/**
* Class for Nokogiri::XML::DocumentFragment
*
*
* @author sergio
* @author Yoko Harada <yokolet@gmail.com>
*/
Expand All @@ -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);
}
Expand All @@ -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])) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 4ba8b4a

Please sign in to comment.