Repository navigation
Gracefully handle input strings with unicode whitespace - #16
Merged
Merged
Conversation
dbernheisel
approved these changes
Nov 22, 2026
Owner
|
Aw man! I hate those little traps! Thanks for contributing. |
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
I was parsing Konversation IRC log files, which unfortunately uses machine-unfriendly timestamps. I encountered the string
2:58:54 PM, which parses as~T[02:58:54]instead of the expected~T[14:58:54]. After a lot of head scratching, I finally realized that the space before thePMis a Unicode U+202F (Narrow Non-Breaking Space), and that was causing DateTimeParser to stop prematurely and discard thePMspecifier.(You might well ask why on earth Konversation is using esoteric whitespace in timestamps. I've certainly been asking myself that.)
After a bunch of digging through Elixir and Erlang regex docs, what I think is happening is that
DateTimeParser.Formatters.cleanisn't canonicalizing unicode whitespace, because by default[[:space:]]only matches on pre-Unicode posix whitespace characters.For the regression tests, I deliberately did not use the test_parsing macros, because the resulting entries in EXAMPLES.livemd repeat other examples as far as the datetime formats go, and the esoteric unicode whitespace isn't obvious to the naked eye.