Skip to content

Commit

Permalink
Fixes JRUBY-6685. 1.9 mode needs its own way fo converting Java Strin…
Browse files Browse the repository at this point in the history
…g to Ruby String.
  • Loading branch information
yokolet committed Aug 1, 2012
1 parent 77e099a commit c3953c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ext/java/nokogiri/XmlNode.java
Expand Up @@ -551,7 +551,7 @@ protected IRubyObject getNodeName(ThreadContext context) {
str = NokogiriHelpers.getLocalPart(str); str = NokogiriHelpers.getLocalPart(str);
} }
if (str == null) str = ""; if (str == null) str = "";
name = context.getRuntime().newString(str); name = NokogiriHelpers.stringOrBlank(context.getRuntime(), str);
return name; return name;
} }


Expand Down
14 changes: 12 additions & 2 deletions ext/java/nokogiri/internals/NokogiriHelpers.java
Expand Up @@ -63,6 +63,7 @@
import nokogiri.XmlProcessingInstruction; import nokogiri.XmlProcessingInstruction;
import nokogiri.XmlText; import nokogiri.XmlText;


import org.jcodings.specific.UTF8Encoding;
import org.jruby.Ruby; import org.jruby.Ruby;
import org.jruby.RubyArray; import org.jruby.RubyArray;
import org.jruby.RubyClass; import org.jruby.RubyClass;
Expand Down Expand Up @@ -179,7 +180,7 @@ public static RubyClass getNokogiriClass(Ruby ruby, String name) {


public static IRubyObject stringOrNil(Ruby runtime, String s) { public static IRubyObject stringOrNil(Ruby runtime, String s) {
if (s == null) return runtime.getNil(); if (s == null) return runtime.getNil();
return RubyString.newString(runtime, s); return convertJavaStringToRuby(runtime, s);
} }


public static IRubyObject stringOrNil(Ruby runtime, byte[] bytes) { public static IRubyObject stringOrNil(Ruby runtime, byte[] bytes) {
Expand All @@ -189,7 +190,16 @@ public static IRubyObject stringOrNil(Ruby runtime, byte[] bytes) {


public static IRubyObject stringOrBlank(Ruby runtime, String s) { public static IRubyObject stringOrBlank(Ruby runtime, String s) {
if (s == null) return runtime.newString(); if (s == null) return runtime.newString();
return RubyString.newString(runtime, s); return convertJavaStringToRuby(runtime, s);
}

private static IRubyObject convertJavaStringToRuby(Ruby runtime, String str) {
if (runtime.is1_9()) {
ByteList bytes = new ByteList(str.getBytes(RubyEncoding.UTF8), UTF8Encoding.INSTANCE);
return RubyString.newString(runtime, bytes);
} else {
return RubyString.newString(runtime, str);
}
} }


/** /**
Expand Down

0 comments on commit c3953c2

Please sign in to comment.