Fix: Match links to a single file with their dot extensions#157
Fix: Match links to a single file with their dot extensions#157nathonius merged 6 commits intonathonius:mainfrom joshleaves:fix/156-linking-to-file
Conversation
|
This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation. |
|
Apologies for the delay, it's been a very busy time for me. I'll try and look at this before the new year. |
|
No problem, hope you're taking enough rest for the year's end. And thanks again for all your work on the extension |
|
So this will work to fix urls that are a file path, but it will cause problems if used within a sentence, for example:
So I think we need to be smarter about this, but I'm not sure how. 🤔 I played around with the regex for a while and came up with this: https://regex101.com/r/bXPVza/1 After this PR goes in I think I'll add some unit tests for various URLs that should and should not match and refine the regex. |
I'd like to work on that, since now the brain teaser got to me =D |
well... I don't have the framework set up yet, and that's something I'd prefer to handle myself 😅 but always happy for contributions otherwise |
|
I added some more tests to the capture regexp since it was also capturing the first word after the repo. |
|
|
@all-contributors please add @joshleaves for code and tests |
|
I've put up a pull request to add @joshleaves! 🎉 |
claremacrae
left a comment
There was a problem hiding this comment.
These are great tests....
For safety, if anyone cared, they could be augmented by checking for cases that should not be matched...
const NON_GITHUB_URLS = [
// a few things that are similar to URLs, and could be confused for them
];
test('does not match string similar to URL', () => {
NON_GITHUB_URLS(url => {
// ......
});
});




Tentative fix for #156 .
I thought the issue came from url-parse.ts but nothing in the code was wrong, so I went up the chain, until I found that the initial decorator matcher was stopping at whitespace, commas,...and the dot character. The matcher was always sending a truncated path to parse-url.
Removing it and testing locally got me the expected result.
And of course, the
hrefvalue is the expected one.