Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

…g to Ruby String.
  • Loading branch information...
commit c3953c2611798d3a9723fe8c040b181217243ba1 1 parent 77e099a
Yoko Harada yokolet authored
2  ext/java/nokogiri/XmlNode.java
@@ -551,7 +551,7 @@ protected IRubyObject getNodeName(ThreadContext context) {
551 551 str = NokogiriHelpers.getLocalPart(str);
552 552 }
553 553 if (str == null) str = "";
554   - name = context.getRuntime().newString(str);
  554 + name = NokogiriHelpers.stringOrBlank(context.getRuntime(), str);
555 555 return name;
556 556 }
557 557
14 ext/java/nokogiri/internals/NokogiriHelpers.java
@@ -63,6 +63,7 @@
63 63 import nokogiri.XmlProcessingInstruction;
64 64 import nokogiri.XmlText;
65 65
  66 +import org.jcodings.specific.UTF8Encoding;
66 67 import org.jruby.Ruby;
67 68 import org.jruby.RubyArray;
68 69 import org.jruby.RubyClass;
@@ -179,7 +180,7 @@ public static RubyClass getNokogiriClass(Ruby ruby, String name) {
179 180
180 181 public static IRubyObject stringOrNil(Ruby runtime, String s) {
181 182 if (s == null) return runtime.getNil();
182   - return RubyString.newString(runtime, s);
  183 + return convertJavaStringToRuby(runtime, s);
183 184 }
184 185
185 186 public static IRubyObject stringOrNil(Ruby runtime, byte[] bytes) {
@@ -189,7 +190,16 @@ public static IRubyObject stringOrNil(Ruby runtime, byte[] bytes) {
189 190
190 191 public static IRubyObject stringOrBlank(Ruby runtime, String s) {
191 192 if (s == null) return runtime.newString();
192   - return RubyString.newString(runtime, s);
  193 + return convertJavaStringToRuby(runtime, s);
  194 + }
  195 +
  196 + private static IRubyObject convertJavaStringToRuby(Ruby runtime, String str) {
  197 + if (runtime.is1_9()) {
  198 + ByteList bytes = new ByteList(str.getBytes(RubyEncoding.UTF8), UTF8Encoding.INSTANCE);
  199 + return RubyString.newString(runtime, bytes);
  200 + } else {
  201 + return RubyString.newString(runtime, str);
  202 + }
193 203 }
194 204
195 205 /**

0 comments on commit c3953c2

Please sign in to comment.
Something went wrong with that request. Please try again.