Skip to content

Commit 2175b9d

Browse files
Copilotweshaggard
authored andcommitted
Fix regex to handle query params and fragments, add edge case tests
Co-authored-by: weshaggard <[email protected]>
1 parent d2a9cb3 commit 2175b9d

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

eng/common/scripts/Verify-Links.ps1

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,14 @@ function ProcessNpmLink([System.Uri]$linkUri) {
166166

167167
# Handle versioned URLs: https://www.npmjs.com/package/@azure/ai-agents/v/1.1.0 -> https://registry.npmjs.org/@azure/ai-agents/1.1.0
168168
# Handle non-versioned URLs: https://www.npmjs.com/package/@azure/ai-agents -> https://registry.npmjs.org/@azure/ai-agents
169-
# The regex captures the package name (which may contain a slash for scoped packages) and optionally the version
169+
# The regex captures the package name (which may contain a slash for scoped packages) and optionally the version.
170+
# Query parameters and URL fragments are excluded from the transformation.
170171
$urlString = $linkUri.ToString()
171-
if ($urlString -match '^https?://(?:www\.)?npmjs\.com/package/(.+)/v/(.+)$') {
172+
if ($urlString -match '^https?://(?:www\.)?npmjs\.com/package/([^?#]+)/v/([^?#]+)') {
172173
# Versioned URL: remove the /v/ segment but keep the version
173174
$apiUrl = "https://registry.npmjs.org/$($matches[1])/$($matches[2])"
174175
}
175-
elseif ($urlString -match '^https?://(?:www\.)?npmjs\.com/package/(.+)$') {
176+
elseif ($urlString -match '^https?://(?:www\.)?npmjs\.com/package/([^?#]+)') {
176177
# Non-versioned URL: just replace the domain
177178
$apiUrl = "https://registry.npmjs.org/$($matches[1])"
178179
}

0 commit comments

Comments
 (0)