note description: "Argument validator" author: "Patrick Ruckstuhl " date: "$Date$" revision: "$Revision$" class ARGUMENT_VALIDATOR feature {NONE} -- User data is_valid_name (a_str: STRING): BOOLEAN -- Is a_str a valid name? require a_str_set: a_str /= Void local l_regexp: RX_PCRE_REGULAR_EXPRESSION do l_regexp := name_regexp l_regexp.match (a_str) Result := l_regexp.has_matched end is_valid_project (a_str: STRING): BOOLEAN -- Is a_str a valid project name? require a_str_set: a_str /= Void local l_regexp: RX_PCRE_REGULAR_EXPRESSION do l_regexp := project_regexp l_regexp.match (a_str) Result := l_regexp.has_matched end is_valid_community (a_str: STRING): BOOLEAN -- Is a_str a valid community name? require a_str_set: a_str /= Void local l_regexp: RX_PCRE_REGULAR_EXPRESSION do l_regexp := community_regexp l_regexp.match (a_str) Result := l_regexp.has_matched end is_valid_email (a_str: STRING): BOOLEAN -- Is a_str a valid email? require a_str_set: a_str /= Void local l_regexp: RX_PCRE_REGULAR_EXPRESSION do l_regexp := email_regexp l_regexp.match (a_str) Result := l_regexp.has_matched and a_str.count <= 100 end is_valid_url (a_str: STRING): BOOLEAN -- Is a_str a valid url? require a_str_set: a_str /= Void local l_regexp: RX_PCRE_REGULAR_EXPRESSION do l_regexp := url_regexp l_regexp.match (a_str) Result := l_regexp.has_matched and a_str.count <= 255 end is_valid_password (a_str: STRING): BOOLEAN -- Is a_str a valid password? require a_str_set: a_str /= Void local l_regexp: RX_PCRE_REGULAR_EXPRESSION do l_regexp := password_regexp l_regexp.match (a_str) Result := l_regexp.has_matched end feature {NONE} -- Authorization is_valid_key (a_str: STRING): BOOLEAN -- Is a_str a valid key? require a_str_set: a_str /= Void local l_regexp: RX_PCRE_REGULAR_EXPRESSION do l_regexp := key_regexp l_regexp.match (a_str) Result := l_regexp.has_matched end is_valid_session (a_str: STRING): BOOLEAN -- Is a_str a valid session? require a_str_set: a_str /= Void local l_regexp: RX_PCRE_REGULAR_EXPRESSION do l_regexp := session_regexp l_regexp.match (a_str) Result := l_regexp.has_matched end is_valid_right (a_str: STRING): BOOLEAN -- Is a_str a valid right? require a_str_set: a_str /= Void local l_regexp: RX_PCRE_REGULAR_EXPRESSION do l_regexp := permission_regexp l_regexp.match (a_str) Result := l_regexp.has_matched end feature {NONE} -- Release and User Picture is_valid_file_name (a_str: STRING): BOOLEAN -- Is a_str a valid file name? require a_str_set: a_str /= Void local l_regexp: RX_PCRE_REGULAR_EXPRESSION do l_regexp := file_name_regexp l_regexp.match (a_str) Result := l_regexp.has_matched end feature {NONE} -- Community is_valid_wiki_title (a_str: STRING): BOOLEAN -- Is a_str a valid wiki title? require a_str_set: a_str /= Void local l_regexp: RX_PCRE_REGULAR_EXPRESSION do l_regexp := wiki_title_regexp l_regexp.match (a_str) Result := l_regexp.has_matched end feature {NONE} -- Onces name_regexp: RX_PCRE_REGULAR_EXPRESSION -- Regular expression that matches valid usernames. once create Result.make Result.compile ("^([a-z])([a-z]|[0-9]|\-|_){1,48}([a-z]|[0-9])$") Result.optimize end project_regexp: RX_PCRE_REGULAR_EXPRESSION -- Regular expression that matches valid project names. once create Result.make Result.compile ("^([a-z])([a-z]|[0-9]|\-){1,48}([a-z]|[0-9])$") Result.optimize end community_regexp: RX_PCRE_REGULAR_EXPRESSION -- Regular expression that matches valid community names. once create Result.make Result.compile ("^([a-z])([a-z]|[0-9]|\-){1,48}([a-z]|[0-9])$") Result.optimize end email_regexp: RX_PCRE_REGULAR_EXPRESSION -- Regular expression that matches valid email addresses. once create Result.make -- valid chars are letters, numbers and !#$%&'*+-/=?^_`.{|}~ Result.compile( "^[\w-!#\$%%&'\*\+-/=\?\^_`\.{}\|~]+@([\w-]+\.)+[\w-]{2,4}$") Result.optimize end url_regexp: RX_PCRE_REGULAR_EXPRESSION -- Regular expression that matches valid url. once create Result.make -- This is not RFC compatble, though it does let through all possible url's -- starting with http or https:// -- domain: may contain letters, hyphens, dots and numbers -- port: optional -- everything after a question mark (except for whitespaces) is legal Result.compile("^https?://([-\w\.]+)+(:\d+)?(/([-#\w/_\.]*(\?\S+)?)?)?$") Result.optimize end password_regexp: RX_PCRE_REGULAR_EXPRESSION -- Regular expression that matches valid password. once create Result.make Result.compile ("^.{6,50}$") Result.optimize end session_regexp: RX_PCRE_REGULAR_EXPRESSION -- Regular expression that matches valid session. once create Result.make Result.compile ("^[A-Z]{32}$") Result.optimize end key_regexp: RX_PCRE_REGULAR_EXPRESSION -- Regular expression that matches valid key. once create Result.make Result.compile ("^[A-Z]{32}$") Result.optimize end permission_regexp: RX_PCRE_REGULAR_EXPRESSION -- Regular expression that matches valid permission. once create Result.make Result.compile ("^[\w_-]{1,30}$") Result.optimize end file_name_regexp: RX_PCRE_REGULAR_EXPRESSION -- Regular expression that matches valid file name. once create Result.make Result.compile ("^[^/*?:<>|]{1,255}$") Result.optimize end wiki_title_regexp: RX_PCRE_REGULAR_EXPRESSION -- Regular expression that matches a valid wiki title. once create Result.make Result.compile ("^[a-zA-Z0-9]((\w|\-| )*[a-zA-Z0-9])?$") Result.optimize end end