Skip to content

Commit

Permalink
fix dynamic regex definitions for schema validation with colander>=2 …
Browse files Browse the repository at this point in the history
…that modifies URL_REGEX pattern (relates to Pylons/colander#352)
  • Loading branch information
fmigneault committed Jan 23, 2023
1 parent ea6c359 commit 38925ca
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
3 changes: 2 additions & 1 deletion CHANGES.rst
Expand Up @@ -16,7 +16,8 @@ Changes:

Fixes:
------
- No change.
- Fix dynamic regex definitions for schema validation with ``colander>=2`` that modifies ``URL_REGEX`` pattern
(relates to `Pylons/colander#352 <https://github.com/Pylons/colander/pull/352>`_).

.. _changes_4.28.0:

Expand Down
4 changes: 3 additions & 1 deletion weaver/wps_restapi/colander_extras.py
Expand Up @@ -354,7 +354,9 @@ def __init__(self, schemes=None, path_pattern=None, msg=None, flags=re.IGNORECAS
if path_pattern:
if isinstance(path_pattern, RegexPattern):
path_pattern = path_pattern.pattern
regex = f"{regex[:-1] + path_pattern}$"
# depending colander version: $ end-of-line, \Z end-of-string (before \n if any), or \z end-of-string (\0)
index = -2 if regex.lower().endswith(r"\z") else -1 if regex.endswith("$") else 0
regex = rf"{regex[:index] + path_pattern}\Z"
super(SchemeURL, self).__init__(regex, msg=msg, flags=flags)


Expand Down

0 comments on commit 38925ca

Please sign in to comment.