Skip to content
This repository has been archived by the owner on Sep 28, 2021. It is now read-only.

Commit

Permalink
fix: improve user input regexes (#111)
Browse files Browse the repository at this point in the history
fix: more permissive user agent regex
refactor: regexes
  • Loading branch information
paulypeter committed Jun 12, 2021
1 parent d2443ec commit b925a01
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
5 changes: 3 additions & 2 deletions src/common.py
Expand Up @@ -7,10 +7,11 @@
APPOINTMENT_URL = r"https://www.impfportal-niedersachsen.de/portal/#/appointment/public"

ZIP_REGEX = r"^(19|21|26|27|28|29|30|31|34|37|38|48|49)([0-9]{3})$"
BIRTHDATE_REGEX = r"^[0-3]?[0-9]\.[0-3]?[0-9]\.(?:[0-9]{2})?[0-9]{2}$"
BIRTHDATE_REGEX = r"^[0-3]?[0-9]\.[0-3]?[0-9]\.(?:19|20)?[0-9]{2}$"
NUMBER_REGEX = r"^[0-9]*(?:\.[0-9])?$"
GROUP_SIZE_REGEX = r"^[2-9]|1[0-5]$"
BOOL_REGEX = r"(?i)^(?:true)|(?:false)$"
USER_AGENT_REGEX = r"^[^ ]*$"
USER_AGENT_REGEX = r"^.*$"


MAIL_REGEX = r"\b(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|\"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*\")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9]))\.){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])\b"
Expand Down
16 changes: 11 additions & 5 deletions src/config_generator.py
@@ -1,7 +1,13 @@
""" generate a config if none found """
import re

from common import NOTIFIERS, NOTIFIER_REGEX, ZIP_REGEX
from common import (
NOTIFIERS,
NOTIFIER_REGEX,
ZIP_REGEX,
GROUP_SIZE_REGEX,
BIRTHDATE_REGEX
)
from config_skeleton import SKELETON

try:
Expand Down Expand Up @@ -164,7 +170,7 @@ def validate_input():
""" validate user input """
if search_group_appointments.get():
entered_group_size = group_size.get()
match_group_size = re.match(r"^[2-9]|1[0-5]$", entered_group_size)
match_group_size = re.match(GROUP_SIZE_REGEX, entered_group_size)
if match_group_size is None:
return False
entered_plz = plz.get()
Expand Down Expand Up @@ -295,14 +301,14 @@ def get_notifier_credentials(notifier):
config_for_group = config_for_group_input.lower() == "j"
while match is None and not config_for_group:
birthday = input('Bitte den Geburtstag eingeben: ')
match = re.match(r"\b\d{1,2}\.\d{1,2}\.\d{4}\b", birthday)
match = re.match(BIRTHDATE_REGEX, birthday)
match = None
while match is None and config_for_group:
group_size = input('Bitte die Gruppengröße eingeben: ')
match = re.match(r"^[2-9]|1[0-5]$", group_size)
match = re.match(GROUP_SIZE_REGEX, group_size)
while match is None or bool(re.match(ZIP_REGEX, plz)):
plz = input('Bitte die PLZ eingeben: ')
match = re.match(r"\b\d{5}\b", plz)
match = re.match(ZIP_REGEX, plz)

enable_notifier = {}
for notifier in FIELDS:
Expand Down
12 changes: 10 additions & 2 deletions src/config_skeleton.py
@@ -1,7 +1,15 @@
"""skelton data for the settings"""

from datetime import datetime
from common import BIRTHDATE_REGEX, BOOL_REGEX, NOTIFIER_REGEX, NUMBER_REGEX, USER_AGENT_REGEX, ZIP_REGEX
from common import (
BIRTHDATE_REGEX,
BOOL_REGEX,
NOTIFIER_REGEX,
NUMBER_REGEX,
USER_AGENT_REGEX,
ZIP_REGEX,
GROUP_SIZE_REGEX
)


SKELETON = {
Expand All @@ -19,7 +27,7 @@
"group_size": {
"default": None,
"type": int,
"regex": NUMBER_REGEX
"regex": GROUP_SIZE_REGEX
}
},
"EMAIL": {
Expand Down

0 comments on commit b925a01

Please sign in to comment.