소스 검색

Validate IRC channel name

master
JustAnotherArchivist 4 년 전
부모
커밋
aa375f81c0
1개의 변경된 파일9개의 추가작업 그리고 8개의 파일을 삭제
  1. +9
    -8
      http2irc.py

+ 9
- 8
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_:


불러오는 중...
취소
저장