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.
This commit is contained in:
Jan Dittberner 2017-09-12 22:13:02 +02:00
parent ff3cc9d940
commit f11114f580

View file

@ -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()])