Skip to content

Commit 43cbb1d

Browse files
committed
Escape package name before using in spawn
Preventing shell expansion using single quotes did not work on Windows as the cmd prompt version of `npm show` would use the quote marks in the api call. The closest specification of npm package names comes from the docs where it says that it must be usable as part of a URL. We don't use encodeURIComponent() as that would escape @ and / as well, so encodeURI is enough. https://docs.npmjs.com/cli/v10/configuring-npm/package-json#name
1 parent c483b98 commit 43cbb1d

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

packages/pluggable-widgets-tools/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
99
### Fixed
1010

1111
- We fixed an issue on Windows where the generated `.mpk` was missing the widget's `.xml` files and icon/tile PNGs.
12+
- We fixed an error thrown by the `audit` command on windows. It would fail when looking up available versions for vulnerable packages.
1213

1314
### Changed
1415

packages/pluggable-widgets-tools/src/commands/audit.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ interface UpdateablePackage {
9797
* Using the ^ version range avoids this, as the version is specific enough for npm.
9898
*/
9999
async function findSafeVersion({ name, range }: NpmAudit.Dependency): Promise<UpdateablePackage> {
100-
const versions = await promisify(exec)(`npm show '${name}' versions --json`).then(
100+
const escapedName = encodeURI(name); // npm package names must be usable as part of a URL
101+
const versions = await promisify(exec)(`npm show ${escapedName} versions --json`).then(
101102
({ stdout }) => JSON.parse(stdout) as string[]
102103
);
103104

0 commit comments

Comments
 (0)