Skip to content

Commit 8bb0ba5

Browse files
committed
fix: sanitize all hyphens in slug generation
1 parent f495de7 commit 8bb0ba5

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,10 +177,10 @@ const hashWithPrefix = (prefix: string, abilityName: string) => {
177177
};
178178

179179
// Sanitize a single string by ensuring the it has only lowercase alpha characters and underscores
180-
const sanitizeSlug = (slug: string) =>
180+
export const sanitizeSlug = (slug: string) =>
181181
slug
182182
.toLowerCase()
183-
.replace("-", "_")
183+
.replace(/-/g, "_")
184184
.replace(/[^a-z0-9_]/gi, "");
185185

186186
export const createAbilityName = (model: string, ability: string) => {

test/unit/sanitizeSlug.spec.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { sanitizeSlug } from "../../src";
2+
3+
describe("sanitizeSlug", () => {
4+
it("replaces all hyphens with underscores", () => {
5+
const slug = "role--with-multiple---hyphens";
6+
expect(sanitizeSlug(slug)).toBe("role__with_multiple___hyphens");
7+
});
8+
});

0 commit comments

Comments
 (0)