-
Notifications
You must be signed in to change notification settings - Fork 81
Open
Description
GitHub allows for the presence of dots in repository names, but the regex to capture and unfurl a URL to a file on GitHub doesn't account for this:
integrations/integrations/github-files/src/github.ts
Lines 8 to 12 in cb7ab97
const splitGithubUrl = (url: string) => { | |
const permalinkRegex = | |
/^https?:\/\/github\.com\/([\w-]+)\/([\w-]+)\/blob\/([a-f0-9]+)\/(.+?)#(.+)$/; | |
const wholeFileRegex = /^https?:\/\/github\.com\/([\w-]+)\/([\w-]+)\/blob\/([\w.-]+)\/(.+)$/; | |
const multipleLineRegex = /^L\d+-L\d+$/; |
This results in the GitHub Files integration not working for files in repositories like Next.js: https://github.com/vercel/next.js/ (instead of the contents of the file, the block in GitBook will display 'Not Found').
Solution is to change the regex for the group that captures the repository name slightly, from ([\w-]+)
to ([\w.-]+)
:
const splitGithubUrl = (url: string) => {
const permalinkRegex =
/^https?:\/\/github\.com\/([\w-]+)\/([\w.-]+)\/blob\/([a-f0-9]+)\/(.+?)#(.+)$/;
const wholeFileRegex = /^https?:\/\/github\.com\/([\w-]+)\/([\w.-]+)\/blob\/([\w.-]+)\/(.+)$/;
const multipleLineRegex = /^L\d+-L\d+$/;
Note that usernames on GitHub don't allow the inclusion of dots, so this change seems to be necessary for repository names only.
Metadata
Metadata
Assignees
Labels
No labels