[erlang-bugs] function clause in io_lib_fread:fread/4 when running out of input before format

Klas Johansson klas.johansson@REDACTED
Wed Jul 20 12:11:45 CEST 2011


Hi,

Stumbled upon a bug in io_lib (rather in io_lib_fread) when parsing
ISO 8601 timestamps.

Given that I parse something like "2009-10-17T18:37:26Z" but (by
mistake) leave out the trailing "Z" in the input string I get a
function clause:

    1> io_lib:fread("~4d-~2d-~2dT~2d:~2d:~2dZ", "2009-10-17T18:37:26").
    ** exception error: no function clause matching
                        io_lib_fread:fread("Z",[],19,[26,37,18,17,10,2009])

Same thing if I stop at any of the non-control characters (like a dash
or colon):

    2> io_lib:fread("~4d-~2d-~2dT~2d:~2d:~2dZ", "2009").
    ** exception error: no function clause matching
                        io_lib_fread:fread("-~2d-~2dT~2d:~2d:~2dZ",[],4,[2009])

Minimal (and silly) test case:

    3> io_lib:fread("Z", "").
    ** exception error: no function clause matching
                    io_lib_fread:fread("Z",[],0,[])

I'd expect something like this:

    4> io_lib:fread("~4d-~2d-~2dT~2d:~2d:~2dZ", "2009").
    {more,"~2d-~2dT~2d:~2d:~2dZ",4,[2009]}

Should be easy to fix, but I've resorted to using re.erl for now.


Cheers,
Klas



More information about the erlang-bugs mailing list