From f11114f58047f50d0a71f42e4e24e4bbb1e04b64 Mon Sep 17 00:00:00 2001 From: Jan Dittberner Date: Tue, 12 Sep 2017 22:13:02 +0200 Subject: [PATCH] Strip non hexadecimal characters from GPG fingerprint input This commit removes non hexadecimal characters from entered GPG fingerprint values to allow copy and paste from gpg output. --- debianmemberportfolio/forms.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/debianmemberportfolio/forms.py b/debianmemberportfolio/forms.py index 11f6b14..d4c87fc 100644 --- a/debianmemberportfolio/forms.py +++ b/debianmemberportfolio/forms.py @@ -28,6 +28,7 @@ from wtforms import IntegerField, StringField, RadioField from wtforms.validators import ( AnyOf, DataRequired, Email, Length, Optional, Regexp ) +from string import hexdigits class FingerPrint(Regexp): @@ -40,10 +41,17 @@ class PlainText(Regexp): super(PlainText, self).__init__(r'^[a-zA-Z\-0-9]*$') +def gpg_fingerprint(data): + if data is not None: + return "".join([ + char for char in str(data) if char.lower() in hexdigits]) + return data + + class DeveloperData(FlaskForm): email = StringField('email', validators=[DataRequired(), Email()]) name = StringField('name', validators=[Optional(), DataRequired()]) - gpgfp = StringField('gpgfp', validators=[ + gpgfp = StringField('gpgfp', filters=[gpg_fingerprint], validators=[ Optional(), FingerPrint(), Length(min=32, max=40) ]) username = StringField('username', validators=[Optional(), PlainText()])