fix(slug): fall back to a stable digest for non-ASCII-only input - #39
Open
Apageoflove wants to merge 2 commits into
Open
Apageoflove wants to merge 2 commits into
Apageoflove wants to merge 2 commits into
Conversation
_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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.