Skip to content

Commit

Permalink
Merge pull request #6432 from kares/backport-strptime-java-error
Browse files Browse the repository at this point in the history
[fix] Date._strptime raises Java exception on invalid argument
  • Loading branch information
headius committed Oct 9, 2020
2 parents b9d2c1e + e45a9ad commit 48e7c10
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion core/src/main/java/org/jruby/ext/date/RubyDate.java
Expand Up @@ -1681,7 +1681,8 @@ public static IRubyObject _strptime(ThreadContext context, IRubyObject self, IRu

@JRubyMethod(meta = true)
public static IRubyObject _strptime(ThreadContext context, IRubyObject self, IRubyObject string, IRubyObject format) {
format = TypeConverter.checkStringType(context.runtime, format);
string = string.convertToString();
format = format.convertToString();
return parse(context, string, ((RubyString) format).decodeString());
}

Expand Down
6 changes: 6 additions & 0 deletions test/jruby/test_time.rb
Expand Up @@ -213,4 +213,10 @@ def test_div
end
end

def test_strptime_type_error
assert_raise(TypeError) { Time.strptime(0, '%Y-%m-%d') }
assert_raise(TypeError) { Time.strptime(nil, '%Y-%m-%d') }
assert_raise(TypeError) { Time.strptime('2020-01-01', 0) }
assert_raise(TypeError) { Time.strptime('2020-01-01', nil) }
end
end

0 comments on commit 48e7c10

Please sign in to comment.