Skip to content
Permalink
Browse files
Fix #2342. Java::JavaLang::NullPointerException: org.jruby.RubyString…
….crypt(RubyString.java:2660)
  • Loading branch information
enebo committed Dec 22, 2014
1 parent 53afbbb commit fce7ea8cd28ebbdbf175574e492126865d025ad2
Showing with 9 additions and 2 deletions.
  1. +8 −2 core/src/main/java/org/jruby/RubyString.java
  2. +1 −0 test/externals/ruby1.9/excludes/TestM17NComb.rb
@@ -38,6 +38,7 @@
***** END LICENSE BLOCK *****/
package org.jruby;

import jnr.posix.POSIX;
import org.jcodings.Encoding;
import org.jcodings.EncodingDB;
import org.jcodings.ascii.AsciiTables;
@@ -2657,8 +2658,13 @@ public RubyString crypt(ThreadContext context, IRubyObject other) {
throw context.runtime.newArgumentError("salt too short(need >=2 bytes)");
}

RubyString result = RubyString.newString(context.runtime,
context.runtime.getPosix().crypt(asJavaString(), salt).toString());
POSIX posix = context.runtime.getPosix();
CharSequence cryptedString = posix.crypt(asJavaString(), salt);
// We differ from MRI in that we do not process salt to make it work and we will
// return any errors via errno.
if (cryptedString == null) throw context.runtime.newErrnoFromInt(posix.errno());

RubyString result = RubyString.newString(context.runtime, cryptedString.toString());
result.associateEncoding(ascii8bit);
result.infectBy(this);
result.infectBy(otherStr);
@@ -8,6 +8,7 @@
exclude :test_str_chop, "needs investigation"
exclude :test_str_chr, "needs investigation"
exclude :test_str_count, "needs investigation"
exclude :test_str_crypt, "full of bogus tests"
exclude :test_str_empty?, "needs investigation"
exclude :test_str_end_with?, "needs investigation"
exclude :test_str_include?, "needs investigation"

0 comments on commit fce7ea8

Please sign in to comment.