Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Replace linkRegex with xurls library #6261
Rather than maintaining a complicated regex to match URLs for autolinking, gitea can use this existing go library that takes care of the matching with very little code change to gitea itself:
After spending a while trying to find the perfect regex for all cases this library still works better as it is more flexible than a single regex ever will be.
This passes all current tests and I've added new ones based on URLs mentioned in those issues above.
@@ Coverage Diff @@ ## master #6261 +/- ## ========================================= Coverage ? 38.81% ========================================= Files ? 355 Lines ? 50253 Branches ? 0 ========================================= Hits ? 19504 Misses ? 27920 Partials ? 2829
Thanks much for the feedback! That is exactly right thanks for catching.
Also here is a tiny test program to compare how long this takes vs the current implementation:
The results I got were:
modifiedLinkRegex being a new regex that would try and match all of the URLs mentioned in the bugs above. So this is pretty on par with anything we could have added and doesn't introduce noticeable slowness in real world situations of large content