mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-10-26 06:04:08 +00:00
fix(tools): handle trailing slashes and whitespace in normalizeBaseUrl and addConversation
This commit is contained in:
parent
a93d85adee
commit
85ddb64bfd
2 changed files with 29 additions and 2 deletions
|
|
@ -8,8 +8,8 @@ import { Supermemory } from "supermemory"
|
|||
*/
|
||||
export const normalizeBaseUrl = (url?: string): string => {
|
||||
const defaultUrl = "https://api.supermemory.ai"
|
||||
if (!url) return defaultUrl
|
||||
return url.endsWith("/") ? url.slice(0, -1) : url
|
||||
const trimmed = url?.trim().replace(/\/+$/, "")
|
||||
return trimmed || defaultUrl
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { describe, expect, it } from "vitest"
|
||||
import { makeTurnKey } from "./shared/cache"
|
||||
import { normalizeBaseUrl } from "./shared/context"
|
||||
import {
|
||||
DEFAULT_VALUES,
|
||||
SEARCH_LIMIT_BOUNDS,
|
||||
|
|
@ -157,3 +158,29 @@ describe("makeTurnKey", () => {
|
|||
expect(keyA).not.toBe(keyB)
|
||||
})
|
||||
})
|
||||
|
||||
describe("normalizeBaseUrl", () => {
|
||||
it("returns default URL when input is missing or empty", () => {
|
||||
expect(normalizeBaseUrl()).toBe("https://api.supermemory.ai")
|
||||
expect(normalizeBaseUrl("")).toBe("https://api.supermemory.ai")
|
||||
expect(normalizeBaseUrl(" ")).toBe("https://api.supermemory.ai")
|
||||
})
|
||||
|
||||
it("collapses single and multiple trailing slashes", () => {
|
||||
expect(normalizeBaseUrl("http://localhost:6768/")).toBe(
|
||||
"http://localhost:6768",
|
||||
)
|
||||
expect(normalizeBaseUrl("http://localhost:6768///")).toBe(
|
||||
"http://localhost:6768",
|
||||
)
|
||||
expect(normalizeBaseUrl("https://api.supermemory.ai/")).toBe(
|
||||
"https://api.supermemory.ai",
|
||||
)
|
||||
})
|
||||
|
||||
it("trims whitespace around URLs", () => {
|
||||
expect(normalizeBaseUrl(" http://localhost:6768/ ")).toBe(
|
||||
"http://localhost:6768",
|
||||
)
|
||||
})
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue