From 841397f522837c20bfe11c4f246be27fb6903ce9 Mon Sep 17 00:00:00 2001 From: vprudnikoff Date: Wed, 4 Nov 2026 16:08:27 +0000 Subject: [PATCH] Read a list flag as JSON only when it is wrapped in brackets; exit 5 on a bad JSON list 1.2.24 parsed any value starting with [ as JSON, so a literal such as "[24]7.ai" failed; now only a value both starting with [ and ending with ] is JSON. An invalid JSON list exits with the validation code 5 instead of the general 1, and the new callbacks carry return types. Found by a post-release review of 1.2.24. --- package-lock.json | 4 ++-- package.json | 2 +- src/utils/split-list-flag.ts | 25 +++++++++++++++++-------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/package-lock.json b/package-lock.json index d318e48..612aad4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@linkedapi/linkedin-cli", - "version": "1.2.24", + "version": "1.2.25", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@linkedapi/linkedin-cli", - "version": "1.2.24", + "version": "1.2.25", "license": "MIT", "dependencies": { "@linkedapi/node": "^2.3.21", diff --git a/package.json b/package.json index 2385182..7a8f259 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@linkedapi/linkedin-cli", - "version": "1.2.24", + "version": "1.2.25", "description": "AI-agent-friendly CLI for controlling LinkedIn accounts and retrieving real-time data.", "author": "Linked API", "license": "MIT", diff --git a/src/utils/split-list-flag.ts b/src/utils/split-list-flag.ts index b380578..7ef8e3a 100644 --- a/src/utils/split-list-flag.ts +++ b/src/utils/split-list-flag.ts @@ -1,16 +1,21 @@ +import { Errors } from '@oclif/core'; + +import { EXIT_CODE } from '@core/errors/exit-codes'; + /** - * Splits a list flag into its values: comma-separated, or a JSON array of strings when the flag - * starts with `[`. + * Splits a list flag into its values: comma-separated, or a JSON array of strings when the flag is + * wrapped in `[` and `]`. * * The JSON form exists for values that contain a comma themselves – a "City, Region" location, an * industry such as "Technology, Information and Internet", a company such as "Example Co., Ltd." – - * which a comma list would silently split into separate filters. + * which a comma list would silently split into separate filters. Only a value both starting with + * `[` and ending with `]` is read as JSON, so a literal such as "[24]7.ai" stays a plain value. */ export function splitListFlag(value: string): Array { const trimmedValue = value.trim(); - if (!trimmedValue.startsWith('[')) { - return value.split(',').map((element) => element.trim()); + if (!trimmedValue.startsWith('[') || !trimmedValue.endsWith(']')) { + return value.split(',').map((element): string => element.trim()); } return parseJsonList(trimmedValue); @@ -19,13 +24,17 @@ export function splitListFlag(value: string): Array { function parseJsonList(value: string): Array { const parsedValue = parseJson(value); - if (!Array.isArray(parsedValue) || !parsedValue.every((element) => typeof element === 'string')) { - throw new Error( + if ( + !Array.isArray(parsedValue) || + !parsedValue.every((element): boolean => typeof element === 'string') + ) { + throw new Errors.CLIError( `Invalid list value: ${value}. Expected comma-separated values or a JSON array of strings, e.g. '["Chicago, Illinois","Denver"]'`, + { exit: EXIT_CODE.VALIDATION }, ); } - return parsedValue.map((element) => element.trim()); + return parsedValue.map((element): string => element.trim()); } function parseJson(value: string): unknown {