Skip to content

Commit 5341b7d

Browse files
committed
fix: deduplicate prefix detection using length comparison
Replace duplicated api/0/ detection condition in func() with a length comparison against normalizeEndpoint's output. Since the function only adds at most 1 char (trailing slash), a shorter result indicates the prefix was stripped.
1 parent 928a4ba commit 5341b7d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/commands/api.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1169,9 +1169,13 @@ export const apiCommand = buildCommand({
11691169

11701170
const normalizedEndpoint = normalizeEndpoint(endpoint);
11711171

1172-
// Warn if the user included the /api/0/ prefix (CLI-K1)
1173-
const bare = endpoint.startsWith("/") ? endpoint.slice(1) : endpoint;
1174-
if (bare.startsWith("api/0/") || bare === "api/0") {
1172+
// Detect whether normalizeEndpoint stripped the api/0/ prefix (CLI-K1).
1173+
// normalizeEndpoint only adds at most 1 char (trailing slash), so if the
1174+
// normalized result is shorter than the raw input, the prefix was stripped.
1175+
const rawLen = endpoint.startsWith("/")
1176+
? endpoint.length - 1
1177+
: endpoint.length;
1178+
if (normalizedEndpoint.length < rawLen) {
11751179
log.warn(
11761180
"Endpoint includes the /api/0/ prefix which is added automatically — stripping it to avoid a doubled path"
11771181
);

0 commit comments

Comments
 (0)