🐛 fixed the slug generator to not allow single character slugs #21261
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.
closes #20133 and masks the effects of TryGhost/NQL#20
It is currently possible to create a user, tag, post, etc with a single character slug.
(It is far too easy to do this with users, if your users have names like C. Ann Smythe.)
Single character slugs break things. They break displaying the posts of a user with a single character slug, and displaying posts with a single-character tag slug, and so on.
Since fixing the underlying NQL parser glitch isn't an easy option, this patch tweaks the logic for generating slugs by
(1) not truncating user names during user creating before the second character (so C. Ann Smythe becomes c-ann instead of c)
(2) checking late in the process for single character slugs, and changing them to baseName-slug, such that a post with title 'q' becomes 'post-q', and a user requesting a change to their slug to the slug 't' will be 'user-t' instead, or if they're new and we are generating the slug from their name, they'll be user-t if their whole name is 'T', or t-lastname if there's more to work with.
The one spot where I feel like this could be improved is user-requested slugs from the profile, where slug generation happens on clicking save (I think), rather than the field updating live like the it does with post slugs.