Skip to content

fix(slug): fall back to a stable digest for non-ASCII-only input - #39

Open
Apageoflove wants to merge 2 commits into
tigerless-labs:mainfrom
Apageoflove:fix/slugify-non-ascii-fallback
Open

Apageoflove wants to merge 2 commits into
tigerless-labs:mainfrom
Apageoflove:fix/slugify-non-ascii-fallback

Conversation

@Apageoflove

Copy link
Copy Markdown

slugify strips all non-ASCII characters via NFKD + encode("ascii", "ignore"), so pure CJK, Arabic, or Cyrillic input produces an empty string. _write_one uses this as the filename fallback, which means every non-ASCII memory without an explicit name collides at the same .md path.

The empty result also fails is_valid_slug, but the error surfaces as "must be a kebab-case slug" which doesn't tell you the abstract was the problem.

This adds a fallback: when the ASCII fold is empty, return a SHA-256 digest of the original text truncated to max_length. The slug is non-empty, deterministic across calls, and stable for migration purposes. Mixed input (like 重构 pipeline v2) is unaffected because the fold produces usable ASCII.

_in_scope used raw startswith(scope), so scope=user also matched
username/, user-notes/, user2/, and any domain whose name begins
with user. Fix: strip trailing slash, then require exact match or
a directory separator after the prefix.
…n empty slug

NFKD + ascii-ignore strips all non-ASCII characters, so pure CJK,
Arabic, or Cyrillic input produces an empty string. The empty slug
passes through _write_one and collides with every other nameless
memory at the same path.

Fall back to a SHA-256 digest of the original text when the fold is
empty, so the slug is non-empty and deterministic.
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.

1 participant