Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve github regexes #3643

Closed
wants to merge 1 commit into from

Conversation

knl
Copy link
Contributor

@knl knl commented May 30, 2020

The existing regexes were incorrect, because they would allow long owner names,
which are not allowed, or in a format that is not appropriate (for example,
containing consecutive -.

According to the form validation messages on Join Github page,

  • Github username (owner) may only contain alphanumeric characters or hyphens.
  • Github username (owner) cannot have multiple consecutive hyphens.
  • Github username (owner) cannot begin or end with a hyphen.
  • Maximum is 39 characters.

Similarly, the repository name can contain any alphanumeric, ., -, and _.

@knl knl marked this pull request as draft May 30, 2020 11:11
The existing regexes were incorrect, because they would allow long owner names,
which are not allowed, or in a format that is not appropriate (for example,
containing consecutive `-`.

According to the form validation messages on Join Github page,
- Github username (owner) may only contain alphanumeric characters or hyphens.
- Github username (owner) cannot have multiple consecutive hyphens.
- Github username (owner) cannot begin or end with a hyphen.
- Maximum is 39 characters.

Similarly, the repository name can contain any alphanumeric, ., -, and _.
@knl knl force-pushed the fix-github-owner-and-repo-regexes branch from 88f9a3e to 88c62ea Compare May 30, 2020 11:32
@knl knl marked this pull request as ready for review May 30, 2020 11:44
// - Github username (owner) may only contain alphanumeric characters or hyphens.
// - Github username (owner) cannot have multiple consecutive hyphens.
// - Github username (owner) cannot begin or end with a hyphen.
// - Maximum is 39 characters.
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add some unit tests for these cases with google test? E.g.
https://github.com/NixOS/nix/pulls?q=is%3Apr+is%3Aclosed+unit+tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. However, I noticed that these regexes are actually not used. I suspect the flakes branch uses them. Could you confirm that?

Copy link
Member

Choose a reason for hiding this comment

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

The flake branch uses those regexes. Both for GitLab and Github. Do you know if they have the same limitations?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hah, they don't have the same limits!

GitLab is even quirkier:

  • username can contain alphanumerics, -, _, and .
  • cannot end with .git and .atom
  • max length is 255 chars

Project name has:

  • max length of 255 chars
  • can contain only letters, digits, emojis, '_', '.', dash, space.
  • It must start with letter, digit, emoji or '_'."

However, the max length of a path is 255 chars. Thus username/projectname in sum should be up to 255 chars... Oh boy.

Sources:

Copy link
Member

Choose a reason for hiding this comment

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

What's actually the advantage of Nix validating GitHub/GitLab org/repo names? We're not doing anything with them except pass them along.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

What's actually the advantage of Nix validating GitHub/GitLab org/repo names? We're not doing anything with them except pass them along.

That's what I've been asking myself. But since the code is there (I was on the verge on removing it before seeing the flakes branch), so since it is used better to make it used correctly.

The advantage of validating the org/repo names is that we could provide a better error message. Disadvantage is that we need to play catch-up (although, I don't think these limits will change).

Copy link
Member

Choose a reason for hiding this comment

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

Note that the flake branch doesn't actually use these regexes anymore (not really a conscious decision, I think the code to check them got lost somewhere) so I deleted them in 5633c09.

It might be a good idea to at least check for names like .. since they might have security implications.

@knl knl closed this Jun 8, 2020
@knl knl deleted the fix-github-owner-and-repo-regexes branch June 8, 2020 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants