Skip to content

Commit 8245ce3

Browse files
PanaetiusRalf Grubenmann
andauthored
fix(core): fix git url regex matching taking too long (#3213)
Co-authored-by: Ralf Grubenmann <[email protected]>
1 parent 4dca1a4 commit 8245ce3

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

renku/domain_model/git.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444

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

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

4949
_RE_PATHNAME_WITH_GITLAB = (
5050
r"(?P<path>((((gitlab/){0,1}|([\w\-\~\.]+/)*?)(?P<owner>([\w\-\.]+/)*[\w\-\.]+)/)?"

tests/core/models/test_git.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"""Git regex tests."""
1919

2020
import os
21+
import time
2122

2223
import pytest
2324

@@ -287,6 +288,15 @@
287288
"port": "1234",
288289
"env": "https://gitlab.example.com:1234/",
289290
},
291+
{
292+
"href": "https://gitlab.example.com/renku-test/test-2022-11-11-17-01-46.git",
293+
"scheme": "https",
294+
"hostname": "gitlab.example.com",
295+
"name": "test-2022-11-11-17-01-46",
296+
"path": "renku-test/test-2022-11-11-17-01-46.git",
297+
"owner": "renku-test",
298+
"env": "https://gitlab.example.com",
299+
},
290300
],
291301
)
292302
def test_valid_href(fields):
@@ -296,4 +306,8 @@ def test_valid_href(fields):
296306
if gitlab_env:
297307
os.environ["GITLAB_BASE_URL"] = gitlab_env
298308

309+
start = time.monotonic()
299310
assert GitURL(**fields) == GitURL.parse(fields["href"])
311+
duration = time.monotonic() - start
312+
313+
assert duration < 1.0, "Something wrong with the GitUrl regexes, probably catastrophic backtracking"

0 commit comments

Comments
 (0)