Skip to content

Commit df7864d

Browse files
committed
Fix: Add URL encoding for package names in API requests
1 parent 3b63aa2 commit df7864d

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/services/npmService.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ export const fetchPackageInfo = async (
2424
packageName: string
2525
): Promise<PackageInfo> => {
2626
try {
27+
// Encode package name for URL safety
28+
const encodedPackageName = encodeURIComponent(packageName);
29+
2730
// Fetch basic package info from npm registry
2831
const registryResponse = await axios.get(
29-
`${NPM_REGISTRY_URL}/${packageName}`
32+
`${NPM_REGISTRY_URL}/${encodedPackageName}`
3033
);
3134
const versionData = registryResponse.data.versions || {};
3235
const description = registryResponse.data.description;
@@ -45,7 +48,7 @@ export const fetchPackageInfo = async (
4548

4649
// Get download counts for all versions
4750
const downloadsByVersionResponse = await axios.get(
48-
`${NPM_VERSIONS_API_URL.replace("<package-name>", packageName)}`
51+
NPM_VERSIONS_API_URL.replace("<package-name>", encodedPackageName)
4952
);
5053

5154
// map the downloads by version back to each version

0 commit comments

Comments
 (0)