Skip to content
Permalink
Browse files
See if newlines makes that tag work. Less unbreak bizarreness of cryp…
…t with non-ascii encoded strings passed to something expecting clean 8bit strings
  • Loading branch information
enebo committed Dec 4, 2014
1 parent 57c2513 commit 729acbf5f72fa8c62e82ab77758fd9bcc849e9cd
Showing with 5 additions and 1 deletion.
  1. +4 −1 core/src/main/java/org/jruby/RubyString.java
  2. +1 −0 spec/tags/1.8/ruby/core/string/crypt_tags.txt
@@ -2649,14 +2649,17 @@ public IRubyObject prepend(ThreadContext context, IRubyObject other) {
*/
@JRubyMethod(name = "crypt")
public RubyString crypt(ThreadContext context, IRubyObject other) {
Encoding ascii8bit = context.runtime.getEncodingService().getAscii8bitEncoding();
RubyString otherStr = other.convertToString();
otherStr.associateEncoding(ascii8bit);
String salt = otherStr.asJavaString();
if (salt.length() < 2) {
if (otherStr.getByteList().length() < 2) {
throw context.runtime.newArgumentError("salt too short(need >=2 bytes)");
}

RubyString result = RubyString.newString(context.runtime,
context.runtime.getPosix().crypt(asJavaString(), salt).toString());
result.associateEncoding(ascii8bit);
result.infectBy(this);
result.infectBy(otherStr);
return result;
@@ -1 +1,2 @@
fail:String#crypt returns NULL bytes prepended to the string when the salt contains NULL bytes

0 comments on commit 729acbf

Please sign in to comment.