flant / ovpn-admin

Simple web UI to manage OpenVPN users.
Apache License 2.0
1.39k stars 261 forks source link

Fix username validation regex to correctly recognize hyphen (-) #293

Open ogumemura opened 2 weeks ago

ogumemura commented 2 weeks ago

This pull request corrects the regular expression used for username validation to correctly recognize hyphens (-).

Changes Made: Changed the regex pattern from ^([a-zA-Z0-9.-@])+$ to ^([a-zA-Z0-9.-@])+$.

Reason for Change: In the previous regex, the hyphen (-) within the character class was interpreted as a range operator, not as a literal character. This caused usernames with hyphens to be incorrectly marked as invalid. By escaping the hyphen (-), the regex now correctly recognizes it as a literal character. This ensures that usernames containing hyphens are validated properly.

Points of Verification: Confirmed that usernames containing hyphens are now correctly recognized and pass the validation. Verified that other characters (letters, numbers, underscores, dots, and at signs) are still being properly validated. regextest.go.txt