Skip to content

Commit 2f1895f

Browse files
committed
Fixed formatted substring expansion [Bug #16767]
1 parent 1711258 commit 2f1895f

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

strftime.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,9 @@ rb_strftime_with_timespec(VALUE ftime, const char *format, size_t format_len,
331331
s += len; \
332332
if (i > 0) case_conv(s, i, flags); \
333333
if (precision > i) {\
334+
s += i; \
334335
NEEDS(precision); \
336+
s -= i; \
335337
memmove(s + precision - i, s, i);\
336338
memset(s, padding ? padding : ' ', precision - i); \
337339
s += precision; \

test/ruby/test_time.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,13 @@ def test_strftime_too_wide
893893
assert_equal(8192, Time.now.strftime('%8192z').size)
894894
end
895895

896+
def test_strftime_wide_precision
897+
t2000 = get_t2000
898+
s = t2000.strftime("%28c")
899+
assert_equal(28, s.size)
900+
assert_equal(t2000.strftime("%c"), s.strip)
901+
end
902+
896903
def test_strfimte_zoneoffset
897904
t2000 = get_t2000
898905
t = t2000.getlocal("+09:00:00")

0 commit comments

Comments
 (0)