mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
regex: make sure we don't have more than one group in the regex
This commit is contained in:
parent
f8be3e7418
commit
f3be1c585f
3 changed files with 11 additions and 1 deletions
|
@ -1,4 +1,4 @@
|
||||||
# MIT licensed
|
# MIT licensed
|
||||||
# Copyright (c) 2013-2021 lilydjwg <lilydjwg@gmail.com>, et al.
|
# Copyright (c) 2013-2021 lilydjwg <lilydjwg@gmail.com>, et al.
|
||||||
|
|
||||||
__version__ = '2.5'
|
__version__ = '2.6dev'
|
||||||
|
|
|
@ -17,6 +17,8 @@ async def get_version_impl(info):
|
||||||
regex = re.compile(conf['regex'])
|
regex = re.compile(conf['regex'])
|
||||||
except sre_constants.error as e:
|
except sre_constants.error as e:
|
||||||
raise GetVersionError('bad regex', exc_info=e)
|
raise GetVersionError('bad regex', exc_info=e)
|
||||||
|
if regex.groups > 1:
|
||||||
|
raise GetVersionError('multi-group regex')
|
||||||
|
|
||||||
encoding = conf.get('encoding', 'latin1')
|
encoding = conf.get('encoding', 'latin1')
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,14 @@ async def test_missing(get_version, httpbin):
|
||||||
"regex": "foobar",
|
"regex": "foobar",
|
||||||
})
|
})
|
||||||
|
|
||||||
|
async def test_multi_group(get_version, httpbin):
|
||||||
|
with pytest.raises(RuntimeError):
|
||||||
|
await get_version("example", {
|
||||||
|
"source": "regex",
|
||||||
|
"url": httpbin.url + "/base64/" + base64_encode("1.2"),
|
||||||
|
"regex": r"(\d+)\.(\d+)",
|
||||||
|
})
|
||||||
|
|
||||||
async def test_regex_with_tokenBasic(get_version, httpbin):
|
async def test_regex_with_tokenBasic(get_version, httpbin):
|
||||||
assert await get_version("example", {
|
assert await get_version("example", {
|
||||||
"source": "regex",
|
"source": "regex",
|
||||||
|
|
Loading…
Add table
Reference in a new issue