-
Notifications
You must be signed in to change notification settings - Fork 517
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 gettingTOO_SHORT
at this stage might not be trivial, unless we early return fromscan::comment_2822
. Potentially the logic could be that if there is at least one(
then it makes sense to early return theTOO_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 entireTOO_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 theparse_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 returnsTOO_LONG
whenever any tokens are left over from parsing. So I'm not sure howTOO_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.