Skip to content

Commit eb60b23

Browse files
Alon YeshurunCopilot
andcommitted
refactor: precompile host-app version regex and clarify test comments
- Use re.fullmatch() with module-level precompiled _HOST_APP_VERSION_RE instead of re.match() with anchors on every call - Add comments clarifying behavior for invalid version (silently dropped) and invalid app name (host-app omitted entirely) Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 58cfe4c commit eb60b23

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/fabric_cli/client/fab_api_client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
from fabric_cli.client.fab_api_types import ApiResponse
1717
from fabric_cli.core import fab_constant, fab_logger, fab_state_config
18+
19+
_HOST_APP_VERSION_RE = re.compile(r"\d+(\.\d+){0,2}(-[a-zA-Z0-9\.-]+)?")
1820
from fabric_cli.core.fab_exceptions import (
1921
AzureAPIError,
2022
FabricAPIError,
@@ -338,9 +340,7 @@ def _get_host_app() -> str:
338340
host_app_version = os.environ.get(fab_constant.FAB_HOST_APP_VERSION_ENV_VAR)
339341

340342
# validate host_app_version format is a valid version (e.g., 1.0.0)
341-
if host_app_version and re.match(
342-
r"^\d+(\.\d+){0,2}(-[a-zA-Z0-9\.-]+)?$", host_app_version
343-
):
343+
if host_app_version and _HOST_APP_VERSION_RE.fullmatch(host_app_version):
344344
host_app += f"/{host_app_version}"
345345
return host_app
346346

tests/test_core/test_fab_api_client.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ def __init__(self):
331331
("Invalid-App", "1.0.0", ""),
332332
("", None, ""),
333333
(None, None, ""),
334+
# Invalid version format - host app is still included but version is silently dropped
334335
(
335336
"Fabric-AzureDevops-Extension",
336337
"1.2.0.4", # Invalid format
@@ -422,6 +423,7 @@ def setup_default_private_links(mock_fab_set_state_config):
422423
"1.2.0",
423424
" host-app/fabric-azuredevops-extension/1.2.0",
424425
),
426+
# Invalid app name - host-app suffix is omitted entirely from User-Agent
425427
("Invalid-App", "1.0.0", ""),
426428
],
427429
)

0 commit comments

Comments
 (0)