Bug
The WordPress importer passes custom post type slugs through to EmDash collection slugs without sanitization. WordPress allows dashes in post type keys (e.g. my-custom-type), but EmDash's SLUG_VALIDATION_PATTERN only allows lowercase letters, numbers, and underscores (/^[a-z][a-z0-9_]*$/). This causes the import to fail for any custom post type containing a dash.
Reproduction
- Export a WordPress site that has a custom post type with a dash in the key (e.g.
book-review)
- Run
emdash import wordpress export.xml --execute
- Import fails with:
collection slug must start with a letter and contain only lowercase letters, numbers, and underscores
Cause
In packages/emdash/src/cli/commands/import/wordpress.ts, the mapPostTypeToCollection function (line ~445) returns unmapped post types as-is:
function mapPostTypeToCollection(postType: string): string {
const mapping: Record<string, string> = {
post: "posts",
page: "pages",
// ...known mappings
};
return mapping[postType] || postType; // no sanitization
}
The slug validation in packages/emdash/src/schema/registry.ts (line 27) then rejects it:
const SLUG_VALIDATION_PATTERN = /^[a-z][a-z0-9_]*$/;
Proposed fix
Sanitize the post type slug in mapPostTypeToCollection before returning it:
function mapPostTypeToCollection(postType: string): string {
const mapping: Record<string, string> = {
post: "posts",
page: "pages",
// ...
};
if (mapping[postType]) return mapping[postType];
// Convert dashes to underscores to match EmDash slug requirements
return postType.replace(/-/g, "_");
}
Context
WordPress post type keys: "Must not exceed 20 characters and may only contain lowercase alphanumeric characters, dashes, and underscores." The only incompatibility is the dash, so a simple replace(/-/g, "_") covers all cases.
Bug
The WordPress importer passes custom post type slugs through to EmDash collection slugs without sanitization. WordPress allows dashes in post type keys (e.g.
my-custom-type), but EmDash'sSLUG_VALIDATION_PATTERNonly allows lowercase letters, numbers, and underscores (/^[a-z][a-z0-9_]*$/). This causes the import to fail for any custom post type containing a dash.Reproduction
book-review)emdash import wordpress export.xml --executecollection slug must start with a letter and contain only lowercase letters, numbers, and underscoresCause
In
packages/emdash/src/cli/commands/import/wordpress.ts, themapPostTypeToCollectionfunction (line ~445) returns unmapped post types as-is:The slug validation in
packages/emdash/src/schema/registry.ts(line 27) then rejects it:Proposed fix
Sanitize the post type slug in
mapPostTypeToCollectionbefore returning it:Context
WordPress post type keys: "Must not exceed 20 characters and may only contain lowercase alphanumeric characters, dashes, and underscores." The only incompatibility is the dash, so a simple
replace(/-/g, "_")covers all cases.