mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-12 22:14:37 +00:00
fix(ui): strip trailing dashes in slugify (#1387)
slugify's docstring promises "no leading/trailing dashes" and the sibling isValidSlug rejects a trailing dash, but slugify only stripped leading dashes. Any input ending in a non-[a-z0-9] character (e.g. "hello world!", a trailing space, "trailing---") produced a slug ending in "-" that then failed isValidSlug, causing invalid persisted keys and spurious validation errors on agent/channel/provider/cron/mcp name fields. Add a symmetric trailing-dash strip, matching the Go helpers (strings.Trim(s, "-")).
This commit is contained in:
1 parent
a9c7feb99c
commit
e65f70e2ef
2 files changed
+22
-1
No files matched your search
@@ -0,0 +1,20 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { isValidSlug, slugify } from "./slug";
|
||||
|
||||
describe("slugify", () => {
|
||||
it("does not leave a trailing dash and passes isValidSlug", () => {
|
||||
for (const input of ["hello world!", "My Agent ", "trailing---", "café résumé!", " spaced "]) {
|
||||
const s = slugify(input);
|
||||
expect(s.endsWith("-")).toBe(false);
|
||||
expect(isValidSlug(s)).toBe(true);
|
||||
}
|
||||
expect(slugify("hello world!")).toBe("hello-world");
|
||||
});
|
||||
|
||||
it("still handles already-valid slugs and diacritics", () => {
|
||||
expect(slugify("valid-slug")).toBe("valid-slug");
|
||||
expect(slugify("abc")).toBe("abc");
|
||||
expect(slugify("Đà Nẵng")).toBe("da-nang");
|
||||
});
|
||||
});
|
||||
@@ -11,7 +11,8 @@ export function slugify(input: string): string {
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9-]/g, "-")
|
||||
.replace(/-{2,}/g, "-")
|
||||
.replace(/^-+/g, "");
|
||||
.replace(/^-+/g, "")
|
||||
.replace(/-+$/g, "");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user