aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--strftime.c10
-rw-r--r--test/ruby/test_time.rb18
3 files changed, 28 insertions, 5 deletions
diff --git a/ChangeLog b/ChangeLog
index 7d172c7aa9..9e4e5a2949 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,4 +1,7 @@
-Tue May 29 17:28:09 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+Tue May 29 17:28:15 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * strftime.c (rb_strftime_with_timespec): check conversion with locale
+ modifier.
* strftime.c (rb_strftime_with_timespec): colons are valid only for
'z' and must come just before it.
diff --git a/strftime.c b/strftime.c
index 767a852727..8d301e1115 100644
--- a/strftime.c
+++ b/strftime.c
@@ -187,7 +187,7 @@ rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, rb_encodi
long y;
int precision, flags, colons;
char padding;
- enum {LEFT, CHCASE, LOWER, UPPER, LOCALE_O, LOCALE_E};
+ enum {LEFT, CHCASE, LOWER, UPPER};
#define BIT_OF(n) (1U<<(n))
#ifdef MAILHEADER_EXT
int sign;
@@ -222,7 +222,7 @@ rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, rb_encodi
for (; *format && s < endp - 1; format++) {
#define FLAG_FOUND() do { \
- if (precision > 0 || flags & (BIT_OF(LOCALE_E)|BIT_OF(LOCALE_O))) \
+ if (precision > 0) \
goto unknown; \
} while (0)
#define NEEDS(n) do if (s >= endp || (n) >= endp - s - 1) goto err; while (0)
@@ -608,11 +608,13 @@ rb_strftime_with_timespec(char *s, size_t maxsize, const char *format, rb_encodi
case 'E':
/* POSIX locale extensions, ignored for now */
- flags |= BIT_OF(LOCALE_E);
+ if (!format[1] || !strchr("cCxXyY", format[1]))
+ goto unknown;
goto again;
case 'O':
/* POSIX locale extensions, ignored for now */
- flags |= BIT_OF(LOCALE_O);
+ if (!format[1] || !strchr("deHkIlmMSuUVwWy", format[1]))
+ goto unknown;
goto again;
case 'V': /* week of year according ISO 8601 */
diff --git a/test/ruby/test_time.rb b/test/ruby/test_time.rb
index a5087bcbfa..ae1221202b 100644
--- a/test/ruby/test_time.rb
+++ b/test/ruby/test_time.rb
@@ -613,6 +613,11 @@ class TestTime < Test::Unit::TestCase
assert_equal(" 2", t.strftime("%_l"))
end
+ def test_strftime_invalid_flags
+ t = Time.mktime(2001, 10, 1, 2, 0, 0)
+ assert_equal("%4^p", t.strftime("%4^p"), 'prec after flag')
+ end
+
def test_strftime_year
t = Time.utc(1,1,4)
assert_equal("0001", t.strftime("%Y"))
@@ -728,6 +733,19 @@ class TestTime < Test::Unit::TestCase
assert_equal("-000:55:00", t.strftime("%10::z"), bug6323)
end
+ def test_strftime_invalid_modifier
+ t = T2000.getlocal("+09:00")
+ assert_equal("%:y", t.strftime("%:y"), 'invalid conversion after : modifier')
+ assert_equal("%:0z", t.strftime("%:0z"), 'flag after : modifier')
+ assert_equal("%:10z", t.strftime("%:10z"), 'prec after : modifier')
+ assert_equal("%Ob", t.strftime("%Ob"), 'invalid conversion after locale modifier')
+ assert_equal("%Eb", t.strftime("%Eb"), 'invalid conversion after locale modifier')
+ assert_equal("%O0y", t.strftime("%O0y"), 'flag after locale modifier')
+ assert_equal("%E0y", t.strftime("%E0y"), 'flag after locale modifier')
+ assert_equal("%O10y", t.strftime("%O10y"), 'prec after locale modifier')
+ assert_equal("%E10y", t.strftime("%E10y"), 'prec after locale modifier')
+ end
+
def test_delegate
d1 = SimpleDelegator.new(t1 = Time.utc(2000))
d2 = SimpleDelegator.new(t2 = Time.utc(2001))