Skip to content

Commit 27c9f1b

Browse files
committed
fix(api): use cleaned endpoint length for api/0/ prefix detection
The length heuristic that detects api/0/ prefix removal compared against the raw input length. After line-break stripping was added, multi-line pasted endpoints without api/0/ would falsely trigger the warning because line-break removal also reduces string length. Fix: compare against the cleaned (line-break-stripped) input length. Reported by Cursor Bugbot.
1 parent 33dd8c1 commit 27c9f1b

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

src/commands/api.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1204,12 +1204,15 @@ export const apiCommand = buildCommand({
12041204
const normalizedEndpoint = normalizeEndpoint(endpoint);
12051205

12061206
// Detect whether normalizeEndpoint stripped the api/0/ prefix (CLI-K1).
1207-
// normalizeEndpoint only adds at most 1 char (trailing slash), so if the
1208-
// normalized result is shorter than the raw input, the prefix was stripped.
1209-
const rawLen = endpoint.startsWith("/")
1210-
? endpoint.length - 1
1211-
: endpoint.length;
1212-
if (normalizedEndpoint.length < rawLen) {
1207+
// Compare against the cleaned endpoint (line breaks removed, trimmed,
1208+
// leading slash removed) since normalizeEndpoint also strips copy-paste
1209+
// artifacts before the api/0/ check. Without this, line-break removal
1210+
// alone would shrink the length and trigger a false api/0/ warning.
1211+
const cleaned = endpoint.replace(/[ \t]*[\r\n]+[ \t]*/g, "").trim();
1212+
const baseLen = cleaned.startsWith("/")
1213+
? cleaned.length - 1
1214+
: cleaned.length;
1215+
if (normalizedEndpoint.length < baseLen) {
12131216
log.warn(
12141217
"Endpoint includes the /api/0/ prefix which is added automatically — stripping it to avoid a doubled path"
12151218
);

0 commit comments

Comments
 (0)