From 335d202796080e48ed19158b7af379a6d8b75bc8 Mon Sep 17 00:00:00 2001 From: Ivan Dlugos Date: Mon, 26 Oct 2026 12:20:03 +0100 Subject: [PATCH] fix(api): Unescape literal characters in generated API URL types The generator copied a route regex's escapes into the TypeScript union, so a route matching a literal dot, like \.git, came out as '$repositoryId\.git'. oxlint rejects that string as a useless escape. Escaped punctuation is now written as the character itself. Refs CW-2222 --- tests/tools/test_api_urls_to_typescript.py | 5 +++++ tools/api_urls_to_typescript.py | 3 +++ 2 files changed, 8 insertions(+) diff --git a/tests/tools/test_api_urls_to_typescript.py b/tests/tools/test_api_urls_to_typescript.py index dc5532d5ab21..70a7728ba9e0 100644 --- a/tests/tools/test_api_urls_to_typescript.py +++ b/tests/tools/test_api_urls_to_typescript.py @@ -34,6 +34,11 @@ r"^(?P[^/]+)/events/(?P[^/]+):(?P(?:\d+|[A-Fa-f0-9-]{32,36}))/$", ["$organizationIdOrSlug/events/$projectIdOrSlug:$eventId/"], ), + # Escaped literal characters lose their backslash + ( + r"^scm-git/repositories/(?P[0-9]{1,19})\.git/(?P.+)$", + ["scm-git/repositories/$repositoryId.git/$route"], + ), ), ) def test_regexp_to_route(input_regexp, expected) -> None: diff --git a/tools/api_urls_to_typescript.py b/tools/api_urls_to_typescript.py index b8e3c9fe5c3a..487b333e09dd 100644 --- a/tools/api_urls_to_typescript.py +++ b/tools/api_urls_to_typescript.py @@ -152,6 +152,9 @@ def replace_named_group(match: re.Match[str]) -> str: # Handle optional trailing slash route = re.sub(r"/\?$", "/", route) + # Unescape literal characters like \. so the route holds the character itself + route = re.sub(r"\\([^\w\s])", r"\1", route) + # Clean up any double slashes that might have been created route = re.sub(r"/+", "/", route)