Skip to content

Commit

Permalink
Fixed some logic bugs when attempting to shrink elements' slugs to be…
Browse files Browse the repository at this point in the history
… under 255 chars

resolves #3514
  • Loading branch information
brandonkelly committed Dec 4, 2018
1 parent d9ebff9 commit 1137942
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
- Fixed an error that occurred on the System Report utility if any non-bootstrapped modules were configured with an array or callable rather than a string. ([#3507](https://github.com/craftcms/cms/issues/3507))
- Fixed an error that occurred on pages with date or time inputs, if the user’s preferred language was set to Arabic. ([#3509](https://github.com/craftcms/cms/issues/3509))
- Fixed a bug where new entries within sections where site propagation was disabled would show both “Enabled Globally” and “Enabled for [Site Name]” settings. ([#3519](https://github.com/craftcms/cms/issues/3519))
- Fixed a bug where Craft wasn’t reducing the size of elements’ slugs if the resulting URI was over 255 characters. ([#3514](https://github.com/craftcms/cms/issues/3514))

## 3.0.33 - 2018-11-27

Expand Down
12 changes: 4 additions & 8 deletions src/helpers/ElementHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,14 @@ public static function setUniqueUri(ElementInterface $element)
$testUri = self::_renderUriFormat($uriFormat, $element);

// Make sure we're not over our max length.
if (strlen($testUri) > 255) {
if (mb_strlen($testUri) > 255) {
// See how much over we are.
$overage = strlen($testUri) - 255;
$overage = mb_strlen($testUri) - 255;

// Do we have anything left to chop off?
if (strlen($overage) > strlen($element->slug) - strlen($slugWordSeparator . $i)) {
if ($overage < mb_strlen($element->slug)) {
// Chop off the overage amount from the slug
$testSlug = $element->slug;
$testSlug = substr($testSlug, 0, -$overage);

// Update the slug
$element->slug = $testSlug;
$element->slug = mb_substr($element->slug, 0, -$overage);

// Let's try this again.
$i--;
Expand Down

0 comments on commit 1137942

Please sign in to comment.