Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,11 @@ const denyHash = new Set([
const minShaLength = 7

// Username may only contain alphanumeric characters or single hyphens, and
// cannot begin or end with a hyphen*.
// cannot begin or end with a hyphen*. Enterprise Managed Users can have
// underscores.
//
// \* That is: until <https://github.com/remarkjs/remark-github/issues/13>.
const userGroup = '[\\da-z][-\\da-z]{0,38}'
const userGroup = '[\\da-z](?:[-_\\da-z]{0,37}[\\da-z-])?'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll be honest, GPT-5 did most of the work here as my Regex skills aren't good enough to optimize this. Two things needed:

  1. Allow _ in addition to - and a-z
  2. BUT -- make sure _ is not the last character in the string, otherwise this could break markdown formatting

const projectGroup = '(?:\\.git[\\w-]|\\.(?!git)|[\\w-])+'
const repoGroup = '(' + userGroup + ')\\/(' + projectGroup + ')'

Expand Down
20 changes: 20 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,26 @@ test('remarkGithub', async function (t) {
}
})

await t.test(
'should not throw w/ `repository` that belongs to an Enterprise Managed User',
async function () {
const file = await remark()
.use(remarkGfm)
.use(remarkGithub, {repository: 'a_zse/b'})
.process(
new VFile({
cwd: new URL('.', import.meta.url).pathname,
value: '12345678'
})
)

assert.equal(
String(file),
'[`1234567`](https://github.com/a_zse/b/commit/12345678)\n'
)
}
)

await t.test('should support `buildUrl` for mentions', async function () {
const file = await remark()
.use(remarkGfm)
Expand Down