-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Panics when using date with invalid formats #4188
Comments
Isnt this related to the
This panics, and that is exactly what we try to do in in the date.rs. I also noted that
but
So also related to how clap processes that incoming string? not sure :P |
yeah, it should be reported upstream too but we could do a better job handling the error on our side |
They seem to be aware of the issue and want to fix it in version 0.5:
In the meantime, there's not much we can do here except validate the string ourselves before we call the function. |
But how could we validate the string ourselves? We dont know what kind of custom input would be given. Anything that doesnt fall under the defined I also dont understand is how the use of |
one option using the existing code would be: use chrono::format::{Item, strftime::StrftimeItems};
let valid = !Strftimeitems(<your_format_string_here>).any(|i| matches!(i, Item::Error)); If you wanted to get the items themselves while also doing validation you could do: let items: Result<Vec<Item>, String> = StrftimeItems::new(format_string).try_fold(Vec::new(), |mut acc, x| {
match x {
Item::Error => Err(format_string.to_string()),
otherwise => {
acc.push(otherwise);
Ok(acc)
}
}
}); and use alongside however we are keen to improve this, perhaps by providing some helper functions on StrftimeItems, so we are keen to receive any feedback on what kind of API would be suitable |
That's much better! Thanks! |
Fixed a while back by #4240 if I'm not mistaken |
cargo run '+~\x0a~%\x0a'
orcargo run "+␅+%+␄^%)"
crashes with backtraceThe text was updated successfully, but these errors were encountered: