naritta/mruby-fast-strptime

No guard about invalid format (No check about unmatched pattern)

Closed this issue · 5 comments

This library provides no protection about unmatched pattern - so we will get wrong result if we wrote invalid time pattern (and it's very hard to find the root cause).

With wrong time format (N instead of %N here), naruse/strptime reports unmatched pattern:

$ ruby -rstrptime -e 'p Strptime.new("%Y-%m-%d %H:%M:%S.N %z").exec("2017-10-06 13:15:30.0 +00:00")'
-e:1:in `exec': string doesn't match (ArgumentError)
	from -e:1:in `<main>'

But this library returns a surprising time value:

$ mruby -e 'p Strptime.new("%Y-%m-%d %H:%M:%S.N %z").exec("2017-10-06 13:15:30.0 +00:00")'
Sun Mar 15 17:53:20 4444257

I fixed here.
107b53e
d08fdd2

@naritta Are there any special reason to raise RuntimeError instead of ArgumentError?

I fixed here.
de378d3

That works fine for me. Thanks!