Skip to content

Commit

Permalink
fix(core): fix git url regex matching taking too long (#3213)
Browse files Browse the repository at this point in the history
Co-authored-by: Ralf Grubenmann <ralf.grubenmann@gmail.com>
  • Loading branch information
Panaetius and Ralf Grubenmann committed Nov 17, 2022
1 parent 4dca1a4 commit 8245ce3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion renku/domain_model/git.py
Expand Up @@ -44,7 +44,7 @@

_RE_PORT = r":(?P<port>\d+)"

_RE_PATHNAME = r"(?P<path>(([\w\-\~\.]+)/)*?(((?P<owner>([\w\-\.]+/?)+)/)?(?P<name>[\w\-\.]+)(\.git)?)?)/*"
_RE_PATHNAME = r"(?P<path>((\~[\w\-\.]+)/)*?(((?P<owner>[\w\-\./]+?)/)?(?P<name>[\w\-\.]+)(\.git)?)?)/*"

_RE_PATHNAME_WITH_GITLAB = (
r"(?P<path>((((gitlab/){0,1}|([\w\-\~\.]+/)*?)(?P<owner>([\w\-\.]+/)*[\w\-\.]+)/)?"
Expand Down
14 changes: 14 additions & 0 deletions tests/core/models/test_git.py
Expand Up @@ -18,6 +18,7 @@
"""Git regex tests."""

import os
import time

import pytest

Expand Down Expand Up @@ -287,6 +288,15 @@
"port": "1234",
"env": "https://gitlab.example.com:1234/",
},
{
"href": "https://gitlab.example.com/renku-test/test-2022-11-11-17-01-46.git",
"scheme": "https",
"hostname": "gitlab.example.com",
"name": "test-2022-11-11-17-01-46",
"path": "renku-test/test-2022-11-11-17-01-46.git",
"owner": "renku-test",
"env": "https://gitlab.example.com",
},
],
)
def test_valid_href(fields):
Expand All @@ -296,4 +306,8 @@ def test_valid_href(fields):
if gitlab_env:
os.environ["GITLAB_BASE_URL"] = gitlab_env

start = time.monotonic()
assert GitURL(**fields) == GitURL.parse(fields["href"])
duration = time.monotonic() - start

assert duration < 1.0, "Something wrong with the GitUrl regexes, probably catastrophic backtracking"

0 comments on commit 8245ce3

Please sign in to comment.