-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Use stricter boundaries for auto-link detection #6522
Conversation
Currently autolinks use \W for boundary detection which creates many situations of inserting links into places they don't belong (paths, URLs, UUIDs, etc...) This fixes that by replacing \W and only allowing these matches to touch an open paren or bracket (matching what seems to be Github behavior) in addition to whitespace and start of line. Similar for ending boundary as well. Fixes go-gitea#6149 (and probably others)
Replace incorrect test with a value that is a valid username, based on: "Username should contain only alphanumeric, dash ('-'), underscore ('_') and dot ('.') characters."
Codecov Report
@@ Coverage Diff @@
## master #6522 +/- ##
==========================================
+ Coverage 40.4% 40.41% +0.01%
==========================================
Files 404 404
Lines 54089 54089
==========================================
+ Hits 21852 21860 +8
+ Misses 29224 29215 -9
- Partials 3013 3014 +1
Continue to review full report at Codecov.
|
Matching Github behavior
Create a specific capture group for email address and then use FindStringSubmatchIndex to allow for non-matching patterns as boundaries.
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.
Could you add some more test cases to show how this improves things
@zeripath sure, added some more test cases here |
Currently autolinks use \W for boundary detection which creates many
situations of inserting links into places they don't belong (paths,
URLs, UUIDs, etc...)
This fixes that by replacing \W and only allowing these matches to touch
an open paren or bracket (matching what seems to be Github behavior) in
addition to whitespace and start of line. Similar for ending boundary as
well (also allowing for a literal period).
Fixes #6149
(and probably others)
Before:
After: