Skip to content

Commit

Permalink
See if newlines makes that tag work. Less unbreak bizarreness of cryp…
Browse files Browse the repository at this point in the history
…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 729acbf
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
5 changes: 4 additions & 1 deletion core/src/main/java/org/jruby/RubyString.java
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions spec/tags/1.8/ruby/core/string/crypt_tags.txt
@@ -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.