Skip to content

Give emoji-only post titles distinct filenames (#52)#69

Merged
jmacdotorg merged 1 commit into
masterfrom
fix/52-emoji-title-collision
Jun 22, 2026
Merged

Give emoji-only post titles distinct filenames (#52)#69
jmacdotorg merged 1 commit into
masterfrom
fix/52-emoji-title-collision

Conversation

@jmacdotorg

Copy link
Copy Markdown
Owner

Closes #52.

Diagnosis

Plerd::Post::_build_published_filename builds a slug from the title by stripping HTML, turning whitespace into hyphens, and then deleting everything that isn't \w or -:

$filename =~ s/[^\w\-]+//g;

A title made entirely of emoji (or any non-word characters) is reduced to the empty string, so the filename becomes YYYY-MM-DD-.html. Two such posts on the same day — e.g. 😀 and 🎩🎩 — both resolve to 2021-01-19-.html, and one silently overwrites the other on disk.

Fix

When the slug comes out empty, fall back to a short hash of the title:

unless ( length $slug ) {
    $slug = substr( md5_hex( encode_utf8( $self->title ) ), 0, 10 );
}

Distinct titles now get distinct, deterministic filenames (2021-01-19-2a02eac39d.html, 2021-01-19-0c35dfec4f.html), and the value is stable across republishes because it's written back into the source's published_filename metadata on first publish. md5_hex/encode_utf8 come from core Digest::MD5 (already a Plerd dependency) and Encode — no new deps. (Two posts sharing an identical title on the same day still collide, but that's the pre-existing, separate collision class that affects ordinary titles too.)

Test

Adds t/emoji_title.t: publishes two emoji-only titles on the same day and asserts the two published filenames are distinct, non-empty, and that both HTML files actually exist on disk. Failed before the fix, passes now. Full suite green (83 tests).

🤖 Generated with Claude Code

A post whose title is made entirely of characters that can't appear in a
filename (e.g. emoji) slugged down to an empty string, so every such post
on a given day produced the same "YYYY-MM-DD-.html" and silently
overwrote its predecessor.

When the title slug comes out empty, fall back to a short hash of the
title. Distinct titles now get distinct, deterministic, stable filenames.
md5_hex/encode_utf8 come from core Digest::MD5 (already a Plerd
dependency) and Encode.

Adds t/emoji_title.t covering two emoji-only titles on the same day.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@jmacdotorg jmacdotorg merged commit ef3e017 into master Jun 22, 2026
3 checks passed
@jmacdotorg jmacdotorg deleted the fix/52-emoji-title-collision branch June 22, 2026 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emoji-only post titles can introduce filename collisions

1 participant