primait/positional.rs

`FromPositionalRow::from_positional_row` panics on strings shorter than expected

Closed this issue · 0 comments

Deserializing a positional row panics when done over a string that is shorter than expected.

An easy way to replicate this is to try to deserialize empty strings.
As an example, the following test fails, as the deserialization panics instead of returning a Result::Err:

use positional::*;

#[derive(FromPositionalRow, PartialEq, Debug)]
struct Data {
    #[field(size = 2)]
    number: i32,
}

#[test]
fn parse_of_empty_string_fails() {
    let row = Data::from_positional_row("");
    assert!(row.is_err())
}

The only case in which it doesn't panic is when another error (eg. wrong type) is detected before reaching the premature end of the row.

\cc @matteougolotti