Skip to content

Conversation

@Arkaeriit
Copy link
Collaborator

This ensures that no characters from the username
get interpreted by the markdown engine.

Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR strengthens username validation by restricting usernames to only contain ASCII letters, numbers, and hyphens. The change prevents special characters in usernames from being interpreted by the markdown rendering engine.

Key Changes:

  • Replaced character-by-character ASCII printable filtering with a regex-based approach that explicitly allows only [a-zA-Z0-9-]
  • Updated the function comment to accurately reflect the new behavior
  • Removed trailing whitespace on line 164

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

s := ""
name = strings.ReplaceAll(strings.TrimSpace(strings.Split(name, "\n")[0]), // use one trimmed line
" ", "-")
invalidCharactersRegex := regexp.MustCompile(`[^a-zA-Z0-9-]`)
Copy link

Copilot AI Dec 12, 2025

Choose a reason for hiding this comment

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

The regex is being compiled on every function call, which is inefficient. Consider declaring this as a package-level variable using var invalidCharactersRegex = regexp.MustCompile(...) outside the function to compile it only once at initialization time. This will improve performance, especially since cleanName is called for every username validation and change.

Copilot uses AI. Check for mistakes.
Copy link
Collaborator Author

@Arkaeriit Arkaeriit Dec 12, 2025

Choose a reason for hiding this comment

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

I'm not sure if the performance boost would be worth making the code less readable...

This ensures that no characters from the username
get interpreted by the markdown engine.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant