Use str.isalnum and str.isdecimal instead of re.match for ?ae7q and ?qrz input validation

This commit is contained in:
Fran Rogers 2021-01-29 23:43:30 -05:00
parent 4ab4748b9f
commit 483a0bad19
2 changed files with 6 additions and 9 deletions

View File

@ -16,8 +16,6 @@ the GNU General Public License, version 2.
# KC4USA: reserved, no call history, *but* has application history
import re
import aiohttp
from bs4 import BeautifulSoup
@ -46,7 +44,7 @@ class AE7QCog(commands.Cog):
base_url = "http://ae7q.com/query/data/CallHistory.php?CALL="
embed = cmn.embed_factory(ctx)
if not re.match('[A-Z0-9]+$', callsign):
if not callsign.isalnum():
embed = cmn.embed_factory(ctx)
embed.title = "AE7Q History for Callsign"
embed.colour = cmn.colours.bad
@ -120,7 +118,7 @@ class AE7QCog(commands.Cog):
base_url = "http://ae7q.com/query/data/CallHistory.php?CALL="
embed = cmn.embed_factory(ctx)
if not re.match('[A-Z0-9]+$', callsign):
if not callsign.isalnum():
embed = cmn.embed_factory(ctx)
embed.title = "AE7Q Trustee History for Callsign"
embed.colour = cmn.colours.bad
@ -196,7 +194,7 @@ class AE7QCog(commands.Cog):
base_url = "http://ae7q.com/query/data/CallHistory.php?CALL="
embed = cmn.embed_factory(ctx)
if not re.match('[A-Z0-9]+$', callsign):
if not callsign.isalnum():
embed = cmn.embed_factory(ctx)
embed.title = "AE7Q Application History for Callsign"
embed.colour = cmn.colours.bad
@ -276,7 +274,7 @@ class AE7QCog(commands.Cog):
base_url = "http://ae7q.com/query/data/FrnHistory.php?FRN="
embed = cmn.embed_factory(ctx)
if not re.match('[0-9]+$', frn):
if not frn.isdecimal():
embed = cmn.embed_factory(ctx)
embed.title = "AE7Q History for FRN"
embed.colour = cmn.colours.bad
@ -347,7 +345,7 @@ class AE7QCog(commands.Cog):
base_url = "http://ae7q.com/query/data/LicenseeIdHistory.php?ID="
embed = cmn.embed_factory(ctx)
if not re.match('[A-Z][0-9]+$', licensee_id, re.IGNORECASE):
if not licensee_id.isalnum():
embed = cmn.embed_factory(ctx)
embed.title = "AE7Q History for Licensee"
embed.colour = cmn.colours.bad

View File

@ -9,7 +9,6 @@ the GNU General Public License, version 2.
from io import BytesIO
import re
import aiohttp
from lxml import etree
@ -32,7 +31,7 @@ class QRZCog(commands.Cog):
"""Looks up a callsign on [QRZ.com](https://www.qrz.com/). Add `--link` to only link the QRZ page."""
flags = [f.lower() for f in flags]
if not re.match('[A-Z0-9]+$', callsign, re.IGNORECASE):
if not callsign.isalnum():
embed = cmn.embed_factory(ctx)
embed.title = "QRZ Data for Callsign"
embed.colour = cmn.colours.bad