From 63442d1d722b7b5ae0d76da34e50d44531f5acc2 Mon Sep 17 00:00:00 2001 From: mvdbeek Date: Wed, 13 Sep 2023 11:58:43 +0200 Subject: [PATCH] Fix regex validation for global inline flags Fixes https://github.com/galaxyproject/galaxy/issues/16676 --- lib/galaxy/dependencies/pinned-requirements.txt | 1 + lib/galaxy/tools/parameters/validation.py | 5 +++-- packages/app/setup.cfg | 1 + pyproject.toml | 1 + test/unit/app/tools/test_parameter_validation.py | 12 ++++++++++++ 5 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/galaxy/dependencies/pinned-requirements.txt b/lib/galaxy/dependencies/pinned-requirements.txt index e995f6d9c2cc..3cca837b3a8b 100644 --- a/lib/galaxy/dependencies/pinned-requirements.txt +++ b/lib/galaxy/dependencies/pinned-requirements.txt @@ -153,6 +153,7 @@ pyyaml==6.0 ; python_version >= "3.7" and python_version < "3.12" pyzmq==25.1.0 ; python_version >= "3.7" and python_version < "3.12" rdflib==6.2.0 ; python_version >= "3.7" and python_version < "3.12" refgenconf==0.12.2 ; python_version >= "3.7" and python_version < "3.12" +regex==2023.8.8 ; python_version >= "3.7" and python_version < "3.12" repoze-lru==0.7 ; python_version >= "3.7" and python_version < "3.12" requests-oauthlib==1.3.1 ; python_version >= "3.7" and python_version < "3.12" requests-toolbelt==1.0.0 ; python_version >= "3.7" and python_version < "3.12" diff --git a/lib/galaxy/tools/parameters/validation.py b/lib/galaxy/tools/parameters/validation.py index 4df3364011ec..6b67b0200cd8 100644 --- a/lib/galaxy/tools/parameters/validation.py +++ b/lib/galaxy/tools/parameters/validation.py @@ -4,7 +4,8 @@ import abc import logging import os.path -import re + +import regex from galaxy import ( model, @@ -143,7 +144,7 @@ def validate(self, value, trans=None): if not isinstance(value, list): value = [value] for val in value: - match = re.match(self.expression, val or "") + match = regex.match(self.expression, val or "") super().validate(match is not None, value_to_show=val) diff --git a/packages/app/setup.cfg b/packages/app/setup.cfg index 9743bcbcd8af..daaa99ffbb3f 100644 --- a/packages/app/setup.cfg +++ b/packages/app/setup.cfg @@ -66,6 +66,7 @@ install_requires = PyJWT PyYAML refgenconf>=0.12.0 + regex requests SQLAlchemy>=1.4.25,<2 sqlitedict diff --git a/pyproject.toml b/pyproject.toml index bba81c7104df..faf9b58666b0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -93,6 +93,7 @@ python-magic = "*" python-multipart = "*" # required to support form parsing in FastAPI/Starlette PyYAML = "*" refgenconf = ">=0.12.0" +regex = "*" requests = "*" rocrate = "*" Routes = "*" diff --git a/test/unit/app/tools/test_parameter_validation.py b/test/unit/app/tools/test_parameter_validation.py index 77fcfee7030d..a1f9da021b45 100644 --- a/test/unit/app/tools/test_parameter_validation.py +++ b/test/unit/app/tools/test_parameter_validation.py @@ -62,3 +62,15 @@ def test_ExpressionValidator_message(self): ValueError, r"Validator 'value.lower\(\) == \"foo\"' could not be evaluated on '1'" ): p.validate(1) + + def test_RegexValidator_global_flag_inline(self): + # tests that global inline flags continue to work past python 3.10 + p = self._parameter_for( + xml=r""" + + ^(?ims)\s*select\s+.*\s+from\s+.*$ +""" + ) + p.validate("select id from job where id = 1;") + with self.assertRaises(ValueError): + p.validate("not sql")