diff --git a/nvchecker_source/regex.py b/nvchecker_source/regex.py index 0828d4d..1660b4f 100644 --- a/nvchecker_source/regex.py +++ b/nvchecker_source/regex.py @@ -22,9 +22,7 @@ async def get_version_impl(info): res = await session.get(conf['url']) body = res.body.decode(encoding) - try: - version = regex.findall(body) - except ValueError: - if not conf.get('missing_ok', False): - raise GetVersionError('version string not found.') - return version + versions = regex.findall(body) + if not versions and not conf.get('missing_ok', False): + raise GetVersionError('version string not found.') + return versions diff --git a/tests/test_regex.py b/tests/test_regex.py index 97a9af7..e54bca1 100644 --- a/tests/test_regex.py +++ b/tests/test_regex.py @@ -43,6 +43,14 @@ async def test_missing_ok(get_version, httpbin): "missing_ok": True, }) is None +async def test_missing(get_version, httpbin): + with pytest.raises(RuntimeError): + await get_version("example", { + "source": "regex", + "url": httpbin.url + "/base64/" + base64_encode("something not there"), + "regex": "foobar", + }) + async def test_regex_with_tokenBasic(get_version, httpbin): assert await get_version("example", { "source": "regex",