Skip to content

Commit 243bcc1

Browse files
committed
fix(@angular/cli): quote complex range specifiers in package manager
Complex range specifiers that include shell special characters (e.g., '>', '<') can be misinterpreted when not quoted. This change ensures that version ranges are always enclosed in quotes to prevent such issues. A test case has been added to verify that complex specifiers are handled correctly.
1 parent 662eca3 commit 243bcc1

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

packages/angular/cli/src/package-managers/package-manager.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ const METADATA_FIELDS = ['name', 'dist-tags', 'versions', 'time'] as const;
3434
* This is a performance optimization to avoid downloading unnecessary data.
3535
* These fields are the ones required by the CLI for operations like `ng add` and `ng update`.
3636
*/
37-
const MANIFEST_FIELDS = [
37+
export const MANIFEST_FIELDS = [
3838
'name',
3939
'version',
4040
'deprecated',
@@ -444,7 +444,7 @@ export class PackageManager {
444444
version: string,
445445
options: { timeout?: number; registry?: string; bypassCache?: boolean } = {},
446446
): Promise<PackageManifest | null> {
447-
const specifier = `${packageName}@${version}`;
447+
const specifier = `${packageName}@"${version}"`;
448448
const commandArgs = [...this.descriptor.getManifestCommand, specifier];
449449
const formatter = this.descriptor.viewCommandFieldArgFormatter;
450450
if (formatter) {

packages/angular/cli/src/package-managers/package-manager_spec.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*/
88

99
import { Host } from './host';
10-
import { PackageManager } from './package-manager';
10+
import { MANIFEST_FIELDS, PackageManager } from './package-manager';
1111
import { SUPPORTED_PACKAGE_MANAGERS } from './package-manager-descriptor';
1212
import { MockHost } from './testing/mock-host';
1313

@@ -22,6 +22,22 @@ describe('PackageManager', () => {
2222
host.runCommand = runCommandSpy;
2323
});
2424

25+
describe('getRegistryManifest', () => {
26+
it('should quote complex range specifiers', async () => {
27+
const pm = new PackageManager(host, '/tmp', descriptor);
28+
const manifest = { name: 'foo', version: '1.0.0' };
29+
runCommandSpy.and.resolveTo({ stdout: JSON.stringify(manifest), stderr: '' });
30+
31+
await pm.getRegistryManifest('foo', '>=1.0.0 <2.0.0');
32+
33+
expect(runCommandSpy).toHaveBeenCalledWith(
34+
descriptor.binary,
35+
[...descriptor.getManifestCommand, 'foo@">=1.0.0 <2.0.0"', ...MANIFEST_FIELDS],
36+
jasmine.anything(),
37+
);
38+
});
39+
});
40+
2541
describe('getVersion', () => {
2642
it('should fetch the version from the package manager if not cached', async () => {
2743
const pm = new PackageManager(host, '/tmp', descriptor);

0 commit comments

Comments
 (0)