Skip to content

Commit

Permalink
Raise a RangeError when codepoint is invalid for the default internal…
Browse files Browse the repository at this point in the history
… enc.

Signed-off-by: Charles Oliver Nutter <headius@headius.com>
  • Loading branch information
tychobrailleur authored and headius committed May 1, 2013
1 parent d4ef266 commit 1733faa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Binary file modified build_lib/jcodings.jar
Binary file not shown.
1 change: 0 additions & 1 deletion spec/tags/1.9/ruby/core/integer/chr_tags.txt
@@ -1,2 +1 @@
fails:Integer#chr without argument when Encoding.default_internal is not nil and self is greater than 255 raises RangeError if self is invalid as a codepoint in the default internal encoding
fails:Integer#chr with an encoding argument raises RangeError if self is invalid as a codepoint in the specified encoding
9 changes: 7 additions & 2 deletions src/org/jruby/RubyInteger.java
Expand Up @@ -336,11 +336,16 @@ private ByteList fromEncodedBytes(Ruby runtime, Encoding enc, int value) {
} catch (EncodingException ee) {
n = 0;
}

if (n <= 0) throw runtime.newRangeError(this.toString() + " out of char range");

ByteList bytes = new ByteList(n);
enc.codeToMbc(value, bytes.getUnsafeBytes(), 0);

try {
enc.codeToMbc(value, bytes.getUnsafeBytes(), 0);
} catch (EncodingException e) {
throw runtime.newRangeError("invalid codepoint " + String.format("0x%x in ", value) + enc.getCharsetName());
}
bytes.setRealSize(n);
return bytes;
}
Expand Down

0 comments on commit 1733faa

Please sign in to comment.