Skip to content

Commit

Permalink
Showing 2 changed files with 11 additions and 1 deletion.
8 changes: 7 additions & 1 deletion core/src/main/java/org/jruby/util/RubyDateFormatter.java
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@
import java.util.List;
import java.util.Locale;

import jnr.constants.platform.Errno;
import org.jcodings.Encoding;
import org.jcodings.specific.ASCIIEncoding;
import org.joda.time.Chronology;
@@ -548,7 +549,12 @@ public ByteList formatToByteList(List<Token> compiledPattern, DateTime dt, long
throw new Error("FORMAT_SPECIAL is a special token only for the lexer.");
}

output = formatter.format(output, value, type);
try {
output = formatter.format(output, value, type);
} catch (IndexOutOfBoundsException ioobe) {
throw context.runtime.newErrnoFromErrno(Errno.ERANGE, "strftime");
}

// reset formatter
formatter = RubyTimeOutputFormatter.DEFAULT_FORMATTER;

Original file line number Diff line number Diff line change
@@ -119,11 +119,15 @@ static String formatSignedNumber(long value, int width, char padder) {
}
}

private static final int SMALLBUF = 100;

static String padding(String sequence, int width, char padder) {
if (sequence.length() >= width) {
return sequence;
}

if (width > SMALLBUF) throw new IndexOutOfBoundsException("padding width " + width + " too large");

StringBuilder buf = new StringBuilder(width + sequence.length());
for (int i = sequence.length(); i < width; i++) {
buf.append(padder);

0 comments on commit 0e45b9b

Please sign in to comment.