GitbookIO / GitbookIO/integrations
Regex that captures URL in GitHub Files integration doesn't allow for '.' (dot) in repository name
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 131
- Forks
- 96
- Avg merge
- 7h 8m
- Merged PRs (30d)
- 31
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:
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in integrations/github-files/src/github.ts at the permalinkRegex and wholeFileRegex around lines 8-12. Update the repository-name matching behavior and verify that GitHub file URLs for repositories containing dots, such as vercel/next.js, are captured and unfurled instead of displaying Not Found.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100