Permalink
Browse files

Fixes JRUBY-6685. 1.9 mode needs its own way fo converting Java Strin…

…g to Ruby String.
  • Loading branch information...
1 parent 77e099a commit c3953c2611798d3a9723fe8c040b181217243ba1 @yokolet yokolet committed Aug 1, 2012
Showing with 13 additions and 3 deletions.
  1. +1 −1 ext/java/nokogiri/XmlNode.java
  2. +12 −2 ext/java/nokogiri/internals/NokogiriHelpers.java
View
2 ext/java/nokogiri/XmlNode.java
@@ -551,7 +551,7 @@ protected IRubyObject getNodeName(ThreadContext context) {
str = NokogiriHelpers.getLocalPart(str);
}
if (str == null) str = "";
- name = context.getRuntime().newString(str);
+ name = NokogiriHelpers.stringOrBlank(context.getRuntime(), str);
return name;
}
View
14 ext/java/nokogiri/internals/NokogiriHelpers.java
@@ -63,6 +63,7 @@
import nokogiri.XmlProcessingInstruction;
import nokogiri.XmlText;
+import org.jcodings.specific.UTF8Encoding;
import org.jruby.Ruby;
import org.jruby.RubyArray;
import org.jruby.RubyClass;
@@ -179,7 +180,7 @@ public static RubyClass getNokogiriClass(Ruby ruby, String name) {
public static IRubyObject stringOrNil(Ruby runtime, String s) {
if (s == null) return runtime.getNil();
- return RubyString.newString(runtime, s);
+ return convertJavaStringToRuby(runtime, s);
}
public static IRubyObject stringOrNil(Ruby runtime, byte[] bytes) {
@@ -189,7 +190,16 @@ public static IRubyObject stringOrNil(Ruby runtime, byte[] bytes) {
public static IRubyObject stringOrBlank(Ruby runtime, String s) {
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);
+ }
}
/**

0 comments on commit c3953c2

Please sign in to comment.