Detect emails followed by a hyphen - #128
Closed
dyk1454683243-sudo wants to merge 1 commit into
Closed
dyk1454683243-sudo wants to merge 1 commit into
dyk1454683243-sudo wants to merge 1 commit into
Conversation
A hyphen is Unicode punctuation, so it looks like a host terminator, but get_host_terminator() rejects it to avoid compounds such as google.com-based. After a completed email host that hyphen cannot continue the address, so treat - / -- like a comma. --- stays opt-in. Co-authored-by: David <dyk1454683243-sudo@users.noreply.github.com>
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.
Fixes #93
test()treats a comma after a valid email as punctuation, but a hyphen makes the whole match fail:After:
Why
-is in Unicode{P}, so the host terminator's first lookahead accepts it. The second lookahead then rejects every hyphen:That rejection is useful for URL hosts (
google.com-basedshould not become a link). It is the wrong rule for emails: after a completed mail host the hyphen cannot continue the address (domain labels already consume internal hyphens, and emails have no path). Soname@example.com-and mid-text cases likeContact name@example.com- for detailsare missed entirely.Change
Mail hosts use a slightly looser terminator:
-and--are treated like other punctuation.---stays opt-in ({ '---': true }), so the existinguser@example.com---foodefault-null behavior is unchanged.URL host termination is left as-is.
Tests
test/api.test.mjstest/fixtures/links.txt: trailing-/--, mid-text,mailto:, hyphenated domains (user@my-company.com)