Skip to content

Commit 2586e9b

Browse files
authored
fix(types): fix URL building to handle query parameters in sign-in links (#3281)
The buildUrl function was incorrectly concatenating query parameters as part of the pathname, causing malformed URLs for sign-in links with parameters like "?source=vscode". This change separates pathname and search parameters properly, ensuring correct URL construction. Added corresponding test case to verify the fix.
1 parent 3cd58a3 commit 2586e9b

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

.changeset/hip-lands-search.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"kilo-code": patch
3+
---
4+
5+
Fix broken sign-in links

packages/types/src/__tests__/kilocode.test.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,9 @@ describe("URL functions", () => {
282282
expect(getAppUrl("/profile")).toBe("https://kilocode.ai/profile")
283283
expect(getAppUrl("/support")).toBe("https://kilocode.ai/support")
284284
expect(getAppUrl("/sign-in-to-editor")).toBe("https://kilocode.ai/sign-in-to-editor")
285+
expect(getAppUrl("/sign-in-to-editor?source=vscode")).toBe(
286+
"https://kilocode.ai/sign-in-to-editor?source=vscode",
287+
)
285288
})
286289

287290
it("should handle development environment", () => {

packages/types/src/kilocode/kilocode.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,13 @@ function buildUrl(path: string = ""): string {
106106
try {
107107
const backend = new URL(getGlobalKilocodeBackendUrl())
108108
const result = new URL(backend)
109-
result.pathname = path ? ensureLeadingSlash(path) : ""
109+
110+
// Separate pathname and search parameters
111+
const [pathname, search] = path.split("?")
112+
result.pathname = pathname ? ensureLeadingSlash(pathname) : ""
113+
if (search) {
114+
result.search = `?${search}`
115+
}
110116

111117
return removeTrailingSlash(result.toString(), result.pathname)
112118
} catch (error) {

0 commit comments

Comments
 (0)