Skip to content

Commit 1e34cbd

Browse files
CopilotdanielmeppielCopilot
authored
fix: recognize Windows drive-letter absolute paths as local paths in DependencyReference (#435)
* Initial plan * fix: detect Windows absolute paths (drive letters) as local paths in reference.py Co-authored-by: danielmeppiel <51440732+danielmeppiel@users.noreply.github.com> Agent-Logs-Url: https://github.com/microsoft/apm/sessions/9f97de46-d7db-4624-8633-30fdefbcf106 * Update reference.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * Update reference.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: danielmeppiel <51440732+danielmeppiel@users.noreply.github.com> Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 2aeb193 commit 1e34cbd

2 files changed

Lines changed: 26 additions & 2 deletions

File tree

src/apm_cli/models/dependency/reference.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,26 @@ def get_virtual_package_name(self) -> str:
129129
def is_local_path(dep_str: str) -> bool:
130130
"""Check if a dependency string looks like a local filesystem path.
131131
132-
Local paths start with './', '../', '/', or '~'.
132+
Local paths start with './', '../', '/', '~/', '~\\', or a Windows drive
133+
letter (e.g. 'C:\\' or 'C:/').
133134
Protocol-relative URLs ('//...') are explicitly excluded.
134135
"""
135136
s = dep_str.strip()
136137
# Reject protocol-relative URLs ('//...')
137138
if s.startswith('//'):
138139
return False
139-
return s.startswith(('./','../', '/', '~/', '~\\', '.\\', '..\\'))
140+
if s.startswith(('./','../', '/', '~/', '~\\', '.\\', '..\\')):
141+
return True
142+
# Windows absolute paths: drive letter + colon + separator (C:\ or C:/).
143+
# Only ASCII letters A-Z/a-z are valid drive letters.
144+
if (
145+
len(s) >= 3
146+
and (('A' <= s[0] <= 'Z') or ('a' <= s[0] <= 'z'))
147+
and s[1] == ':'
148+
and s[2] in ('\\', '/')
149+
):
150+
return True
151+
return False
140152

141153
def get_unique_key(self) -> str:
142154
"""Get a unique key for this dependency for deduplication.

tests/unit/test_local_deps.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,18 @@ def test_windows_parent(self):
3737
def test_windows_home(self):
3838
assert DependencyReference.is_local_path("~\\repos\\my-pkg") is True
3939

40+
def test_windows_absolute_backslash(self):
41+
assert DependencyReference.is_local_path("C:\\Users\\runner\\my-pkg") is True
42+
43+
def test_windows_absolute_forward_slash(self):
44+
assert DependencyReference.is_local_path("D:/repos/my-pkg") is True
45+
46+
def test_windows_absolute_uppercase(self):
47+
assert DependencyReference.is_local_path("Z:\\some\\path") is True
48+
49+
def test_windows_absolute_lowercase(self):
50+
assert DependencyReference.is_local_path("c:\\users\\me\\pkg") is True
51+
4052
def test_remote_shorthand_not_local(self):
4153
assert DependencyReference.is_local_path("owner/repo") is False
4254

0 commit comments

Comments
 (0)