Skip to content

Conversation

@EvHaus
Copy link
Contributor

@EvHaus EvHaus commented Aug 8, 2025

Initial checklist

  • I read the support docs
  • I read the contributing guide
  • I agree to follow the code of conduct
  • I searched issues and discussions and couldn’t find anything or linked relevant results below
  • I made sure the docs are up to date
  • I included tests (or that’s not needed)

Description of changes

A GitHub Enterprise customer discovered a bug in our product today (that uses remark-github). Their code was crashing with:

Unexpected invalid `repository`, expected for example `user/project`

After a bunch of troubleshooting I discovered it's because their GitHub username has an _ (underscore) in it. Turns out although generally this is not allowed on GitHub, Enterprise Managed Users can have underscores (see official docs).

This PR updates the Regex to support this and adds a unit test to catch this edge case.

@github-actions github-actions bot added 👋 phase/new Post is being triaged automatically 🤞 phase/open Post is being triaged manually and removed 👋 phase/new Post is being triaged automatically labels Aug 8, 2025
//
// \* 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

@wooorm
Copy link
Member

wooorm commented Aug 14, 2025

Do you have an exact quote from the website you are basing this on?
Or, an exact case of input?
From quickly glancing over that (sorry, little time), it seems to say that one underscore is used:

On GitHub.com, GitHub also adds an underscore and your enterprise's shortcode to the end of each username.

Usernames, including underscore and short code, must not exceed 39 characters.

Sounds like perhaps something else is needed, allowing one underscore + shortcode and checking length with code, rather than just allowing arbitrary underscores except at the last character? 🤔

@EvHaus
Copy link
Contributor Author

EvHaus commented Aug 14, 2025

Do you have an exact quote from the website you are basing this on?

Yup -- it's that one that you found: "On GitHub.com, GitHub also adds an underscore and your enterprise's shortcode to the end of each username.".

Or, an exact case of input?

The exact user id I ran into was k-archarya_zse where I think _zse is the GHC instance suffix.

Sounds like perhaps something else is needed, allowing one underscore + shortcode and checking length with code, rather than just allowing arbitrary underscores except at the last character? 🤔

Sure. I can revise the Regex to only check for a single instance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🤞 phase/open Post is being triaged manually

Development

Successfully merging this pull request may close these issues.

2 participants