Disallow uppercased usernames and hostnames
Drive-by: replaced some of the parts by named POSIX character classes to make the regex easier to read.
This commit is contained in:
parent
4f87ab1582
commit
b83619cd2c
1 changed files with 5 additions and 8 deletions
|
|
@ -6,17 +6,14 @@ module Validation
|
||||||
class DiasporaId
|
class DiasporaId
|
||||||
# The Regex for a valid diaspora* ID
|
# The Regex for a valid diaspora* ID
|
||||||
DIASPORA_ID_REGEX = begin
|
DIASPORA_ID_REGEX = begin
|
||||||
letter = "a-zA-Z"
|
username = "[[:lower:]\\d\\-\\.\\_]+"
|
||||||
digit = "0-9"
|
hostname_part = "[[:lower:]\\d\\-]"
|
||||||
hexadecimal = "[a-fA-F#{digit}]"
|
|
||||||
username = "[#{letter}#{digit}\\-\\_\\.]+"
|
|
||||||
hostname_part = "[#{letter}#{digit}\\-]"
|
|
||||||
hostname = "#{hostname_part}+(?:[.]#{hostname_part}*)*"
|
hostname = "#{hostname_part}+(?:[.]#{hostname_part}*)*"
|
||||||
ipv4 = "(?:[#{digit}]{1,3}\\.){3}[#{digit}]{1,3}"
|
ipv4 = "(?:[\\d]{1,3}\\.){3}[\\d]{1,3}"
|
||||||
ipv6 = "\\[(?:#{hexadecimal}{0,4}:){0,7}#{hexadecimal}{1,4}\\]"
|
ipv6 = "\\[(?:[[:xdigit:]]{0,4}:){0,7}[[:xdigit:]]{1,4}\\]"
|
||||||
ip_addr = "(?:#{ipv4}|#{ipv6})"
|
ip_addr = "(?:#{ipv4}|#{ipv6})"
|
||||||
domain = "(?:#{hostname}|#{ip_addr})"
|
domain = "(?:#{hostname}|#{ip_addr})"
|
||||||
port = "(?::[#{digit}]+)?"
|
port = "(?::[\\d]+)?"
|
||||||
|
|
||||||
"#{username}\\@#{domain}#{port}"
|
"#{username}\\@#{domain}#{port}"
|
||||||
end
|
end
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue