mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-01-20 22:42:53 -05:00
🐛 Fixed slugs from exceeding db limit (#9251)
closes #8143 Fixed a potential issue (edge-case), where our generated and validated (in terms of check for existance and add a counter) would return a slug, that will exceed the maximum length of the slug fields (191 chars). This is mostly possible for the post title, which can be 255 chars long and would generate a slug with the same length. This would prevent the user from actually saving a post. I tried first to determine the expected length for a slug that already exists, but decided that the **easier** and simplyfied implementation is to always cut a slug to **185 chars** (+ counter). This makes it easier to find duplicates and includes a possible high number of counts (edge-edge-case). The slug will not be cut down to 185 chars if it's an import.
This commit is contained in:
parent
eba100d965
commit
982a75d6be
1 changed files with 10 additions and 0 deletions
|
@ -712,8 +712,18 @@ ghostBookshelf.Model = ghostBookshelf.Model.extend({
|
|||
});
|
||||
};
|
||||
|
||||
// the slug may never be longer than the allowed limit of 191 chars, but should also
|
||||
// take the counter into count. We reduce a too long slug to 185 so we're always on the
|
||||
// safe side, also in terms of checking for existing slugs already.
|
||||
slug = utils.safeString(base, options);
|
||||
|
||||
if (slug.length > 185) {
|
||||
// CASE: don't cut the slug on import
|
||||
if (!_.has(options, 'importing') || !options.importing) {
|
||||
slug = slug.slice(0, 185);
|
||||
}
|
||||
}
|
||||
|
||||
// If it's a user, let's try to cut it down (unless this is a human request)
|
||||
if (baseName === 'user' && options && options.shortSlug && slugTryCount === 1 && slug !== 'ghost-owner') {
|
||||
longSlug = slug;
|
||||
|
|
Loading…
Add table
Reference in a new issue