-
Notifications
You must be signed in to change notification settings - Fork 533
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
Add compatibility with rfc2822 comments #733
Conversation
276bf3b
to
dcdc18c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good from my perspective - I've just left one comment for some discussion
"Tue, 20 Jan 2015 17:35:20 -0800 ( (UTC ) (\\( (a)\\(( \\t ) ) \\\\( \\) ))", | ||
Ok("Tue, 20 Jan 2015 17:35:20 -0800"), | ||
), // complex trailing comment | ||
("Tue, 20 Jan 2015 17:35:20 -0800 (UTC\\)", Err(TOO_LONG)), // incorrect comment, not enough closing parentheses |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems like TOO_SHORT
is more optimal in this case (admittedly obscure) - but it seems like actually getting TOO_SHORT
at this stage might not be trivial, unless we early return from scan::comment_2822
. Potentially the logic could be that if there is at least one (
then it makes sense to early return the TOO_SHORT
if it is never closed. Alternatively, the parser could be more permissive and just remove all the comment characters and return the parsed date if the rest is in the correct format - let me know what your thoughts are here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had the same thought, but for one, it's indeed not trivial to change that; and further, it's not completely clear. Technically "Tue, 20 Jan 2015 17:35:20 -0800 ("
could be both too short or too long. "Tue, 20 Jan 2015 17:35:20 -0800 x"
, for example, is definitely too long, so one could argue that the first one is also a valid string plus " ("
. So I'd argue that "a comment" is everything that parses as a comment, and "too long" is everything attached to the timestamp that doesn't parse as a comment. Which includes " ("
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think just accepting everything is the right choice, at least not with your current code structure. parse.rs
just parses a single rfc2822 datetime string, and the way it is currently written means it could be used as a part of a more complex parser. So I wouldn't allow just everything, otherwise I think the entire TOO_LONG
value would be pointless and we could simply accept all the strings that start with a valid rfc2822 datetime.
If you want me to change something, then what I would agree with most is to short-circuit TOO_SHORT
. But that also wouldn't be true the way the code is written right now, because the parse_rfc2822
conceptually is supposed to attempt to parse a rfc2822 datetime string + return the leftover input that wasn't part of the rfc2822 datetime. And it does exactly that in the case of "Tue, 20 Jan 2015 17:35:20 -0800 ("
, because "Tue, 20 Jan 2015 17:35:20 -0800"
is a valid rfc2822 string and " ("
is a valid rest. It just wasn't able to consume " ("
, which is totally valid.
So if we want to change something, it must be somewhere in the method parse_internal
. And this one currently is written so that it always returns TOO_LONG
whenever any tokens are left over from parsing. So I'm not sure how TOO_SHORT
would conceptually fit the current code structure.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @Finomnis - really good point about the rfc2822 item being able to be reused within other formats, we definitely shouldn't break that so it looks like it is best to leave it as is.
dcdc18c
to
dd10eac
Compare
@esheppa Rebased to fix merge conflict in |
Thanks @Finomnis |
Fixes #732.