aboutsummaryrefslogtreecommitdiff
path: root/http2irc.py
diff options
context:
space:
mode:
authorGravatar JustAnotherArchivist2020-05-11 20:40:01 +0000
committerGravatar JustAnotherArchivist2020-05-11 20:40:01 +0000
commitaa375f81c00af78227cdc972f3a692ff9daad66e (patch)
tree179f8545d13571c574d8b09b9917be586240cc8b /http2irc.py
parentValidate maps (diff)
signature
Validate IRC channel name
Diffstat (limited to 'http2irc.py')
-rw-r--r--http2irc.py17
1 files changed, 9 insertions, 8 deletions
diff --git a/http2irc.py b/http2irc.py
index 1238f0f..039c078 100644
--- a/http2irc.py
+++ b/http2irc.py
@@ -129,12 +129,14 @@ class Config(dict):
raise InvalidConfig(f'Invalid map {key!r} web path: collides with map {seenWebPaths[map_["webpath"]]!r}')
seenWebPaths[map_['webpath']] = key
- if 'ircchannel' in map_:
- if not isinstance(map_['ircchannel'], str):
- raise InvalidConfig(f'Invalid map {key!r} IRC channel: not a string')
- if not map_['ircchannel'].startswith('#') and not map_['ircchannel'].startswith('&'):
- raise InvalidConfig(f'Invalid map {key!r} IRC channel: does not start with # or &')
- #TODO Check if it's a valid name per IRC spec
+ if 'ircchannel' not in map_:
+ map_['ircchannel'] = f'#{key}'
+ if not isinstance(map_['ircchannel'], str):
+ raise InvalidConfig(f'Invalid map {key!r} IRC channel: not a string')
+ if not map_['ircchannel'].startswith('#') and not map_['ircchannel'].startswith('&'):
+ raise InvalidConfig(f'Invalid map {key!r} IRC channel: does not start with # or &')
+ if any(x in map_['ircchannel'][1:] for x in (' ', '\x00', '\x07', '\r', '\n', ',')):
+ raise InvalidConfig(f'Invalid map {key!r} IRC channel: contains forbidden characters')
if 'auth' in map_:
if map_['auth'] is not False and not isinstance(map_['auth'], str):
@@ -156,8 +158,7 @@ class Config(dict):
# Fill in default values for the maps
for key, map_ in obj['maps'].items():
# webpath is already set above for duplicate checking
- if 'ircchannel' not in map_:
- map_['ircchannel'] = f'#{key}'
+ # ircchannel is set above for validation
if 'auth' not in map_:
map_['auth'] = False
if 'module' not in map_: