Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

fix(slug): accept colon-separated namespace parts

Javier Aldape9cac4b8888f3
diff --git a/src/core/ops/context.ts b/src/core/ops/context.ts
index 0bb8d9eba4..b3088939b5 100644
--- a/src/core/ops/context.ts
+++ b/src/core/ops/context.ts
@@ -79,8 +79,11 @@ export function validateUploadPath(filePath: string, root: string, strict = true
}
/**
- * Op-boundary page-slug segment (#4665): cjk.ts's PAGE_SLUG_SEG shape widened
- * LOCALLY so `.` and `_` are allowed as segment-CONTINUATION characters. The
+ * Op-boundary page-slug segment (#4665/#5032): cjk.ts's PAGE_SLUG_SEG shape
+ * widened LOCALLY so `.` and `_` are allowed as part-CONTINUATION characters.
+ * Colon separates individually valid parts inside a path segment, preserving
+ * existing integration slugs such as `calendar:event-id` without admitting
+ * empty or dot-led parts (`calendar:../x` remains invalid). The
* sync slugifier deliberately preserves both (`notes/v1.0.0`,
* `people/my_file_name` — see slugifySegment in src/core/sync.ts), so the
* put_page boundary must round-trip every slug sync can produce. The lead
@@ -95,13 +98,14 @@ export function validateUploadPath(filePath: string, root: string, strict = true
// underscores (`_index.md` → `_index`, the Hugo convention), so rejecting
// them recreates the un-updatable-synced-page class this widen closes.
// Dot stays continuation-only — `..` traversal remains impossible.
-const OP_PAGE_SLUG_SEG = `[${SLUG_WORD_CHARS}_][${SLUG_WORD_CHARS}._\\-]*`;
+const OP_PAGE_SLUG_PART = `[${SLUG_WORD_CHARS}_][${SLUG_WORD_CHARS}._\\-]*`;
+const OP_PAGE_SLUG_SEG = `${OP_PAGE_SLUG_PART}(?::${OP_PAGE_SLUG_PART})*`;
/**
* Allowlist validator for page slugs. Rejects URL-encoded traversal, backslashes,
* control chars, RTL overrides, Unicode lookalikes — anything outside the allowlist.
- * Format: lowercase alphanumeric segments (dot/underscore/hyphen continuation
- * allowed) separated by single forward slashes.
+ * Format: alphanumeric parts (dot/underscore/hyphen continuation allowed),
+ * optionally colon-separated within segments; segments use single forward slashes.
*/
export function validatePageSlug(slug: string): void {
if (typeof slug !== 'string' || slug.length === 0) {
@@ -114,7 +118,7 @@ export function validatePageSlug(slug: string): void {
// for the \p{...} classes in OP_PAGE_SLUG_SEG). Shape rules (word-char lead,
// dot/underscore/hyphen continuation) preserved.
if (!new RegExp(`^${OP_PAGE_SLUG_SEG}(\\/${OP_PAGE_SLUG_SEG})*$`, 'iu').test(slug)) {
- throw new OperationError('invalid_params', `Invalid page_slug: ${slug} (allowed: letters/numbers in any script, with '.', '_', '-' after the first character of a segment, forward-slash separated segments)`);
+ throw new OperationError('invalid_params', `Invalid page_slug: ${slug} (allowed: letters/numbers in any script, with '.', '_', '-' after the first character of a part, optional colon-separated namespace parts, and forward-slash separated segments)`);
}
}
diff --git a/test/file-upload-security.test.ts b/test/file-upload-security.test.ts
index 9319ed3e18..5e4b2a78fc 100644
--- a/test/file-upload-security.test.ts
+++ b/test/file-upload-security.test.ts
@@ -132,6 +132,18 @@ describe('validatePageSlug', () => {
expect(() => validatePageSlug('people/my_file_name')).not.toThrow();
});
+ it('accepts colon-separated namespace parts (#5032)', () => {
+ expect(() => validatePageSlug('calendar:abc123def456')).not.toThrow();
+ expect(() => validatePageSlug('integrations/calendar:event-123')).not.toThrow();
+ });
+
+ it('rejects empty or dot-led colon namespace parts (#5032)', () => {
+ expect(() => validatePageSlug('calendar:')).toThrow(OperationError);
+ expect(() => validatePageSlug(':event')).toThrow(OperationError);
+ expect(() => validatePageSlug('calendar::event')).toThrow(OperationError);
+ expect(() => validatePageSlug('calendar:../event')).toThrow(OperationError);
+ });
+
it('accepts underscore-LED segments the slugifier produces (Hugo _index shape, #4665)', () => {
// slugifySegment('_index') === '_index' — leading underscores survive
// sync, so the op boundary must round-trip them too. Dots stay