Skip to content
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

Merged
merged 6 commits into from
Apr 7, 2019

Conversation

mrsdizzie
Copy link
Member

@mrsdizzie mrsdizzie commented Apr 5, 2019

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:
Screen Shot 2019-04-05 at 11 50 23 AM

After:
Screen Shot 2019-04-05 at 11 50 46 AM

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-io
Copy link

codecov-io commented Apr 5, 2019

Codecov Report

Merging #6522 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
modules/markup/html.go 82.36% <100%> (+0.43%) ⬆️
routers/repo/view.go 42.07% <0%> (+0.99%) ⬆️
models/unit.go 14.28% <0%> (+14.28%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 5422f23...13df22e. Read the comment docs.

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 5, 2019
@GiteaBot GiteaBot added lgtm/need 1 This PR needs approval from one additional maintainer to be merged. and removed lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. labels Apr 5, 2019
@lafriks lafriks added the type/enhancement An improvement of existing functionality label Apr 5, 2019
@lafriks lafriks added this to the 1.9.0 milestone Apr 5, 2019
Matching Github behavior
Create a specific capture group for email address and then use
FindStringSubmatchIndex to allow for non-matching patterns as
boundaries.
Copy link
Contributor

@zeripath zeripath left a 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

@GiteaBot GiteaBot added lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. and removed lgtm/need 1 This PR needs approval from one additional maintainer to be merged. labels Apr 6, 2019
Add tests for new behavior -- including tests for email addresses which
were absent before.
@mrsdizzie
Copy link
Member Author

@zeripath sure, added some more test cases here

@zeripath zeripath merged commit 6293736 into go-gitea:master Apr 7, 2019
@go-gitea go-gitea locked and limited conversation to collaborators Nov 24, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
lgtm/done This PR has enough approvals to get merged. There are no important open reservations anymore. type/enhancement An improvement of existing functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

uuids not rendered correctly
5 participants