Permalink
Browse files

Fixes for TestM18N#test_sprintf_s

  • Loading branch information...
1 parent 224ff97 commit 61239b373024fca80a5b05f746ed4f1955dcdbad @headius headius committed May 15, 2012
Showing with 11 additions and 6 deletions.
  1. +1 −1 src/org/jruby/RubyString.java
  2. +10 −4 src/org/jruby/util/Sprintf.java
  3. +0 −1 test/externals/ruby1.9/excludes/TestM17N.rb
@@ -335,7 +335,7 @@ private int strLength(Encoding enc) {
return strLength(value, enc);
}
- final int strLength() {
+ public final int strLength() {
if (singleByteOptimizable()) return value.getRealSize();
return strLength(value);
}
@@ -535,22 +535,28 @@ private static boolean rubySprintfToBuffer(ByteList buf, CharSequence charFormat
ByteList bytes = strArg.getByteList();
Encoding enc = wrapper.checkEncoding(strArg);
int len = bytes.length();
+ int strLen = strArg.strLength();
+
if (arg.isTaint()) tainted = true;
+
if ((flags & FLAG_PRECISION) != 0 && precision < len) {
+ // TODO: precision is not considering actual character length
+ // See below as well.
len = precision;
+ strLen = precision;
}
- // TODO: adjust length so it won't fall in the middle
+ // TODO: adjust length so it won't fall in the middle
// of a multi-byte character. MRI's sprintf.c uses tables
// in a modified version of regex.c, which assume some
// particular encoding for a given installation/application.
- // (See regex.c#re_mbcinit in ruby-1.8.5-p12)
+ // (See regex.c#re_mbcinit in ruby-1.8.5-p12)
//
// This is only an issue if the user specifies a precision
// that causes the string to be truncated. The same issue
// would arise taking a substring of a ByteList-backed RubyString.
- if ((flags & FLAG_WIDTH) != 0 && width > len) {
- width -= len;
+ if ((flags & FLAG_WIDTH) != 0 && width > strLen) {
+ width -= strLen;
if ((flags & FLAG_MINUS) != 0) {
buf.append(bytes.getUnsafeBytes(),bytes.begin(),len);
buf.fill(' ',width);
@@ -22,7 +22,6 @@
exclude :test_regexp_unicode, "needs investigation"
exclude :test_regexp_usascii, "needs investigation"
exclude :test_sprintf_c, "needs investigation"
-exclude :test_sprintf_s, "needs investigation"
exclude :test_str_String, "needs investigation"
exclude :test_str_aref_substr, "needs investigation"
exclude :test_str_concat, "needs investigation"

0 comments on commit 61239b3

Please sign in to comment.