Skip to content

Commit

Permalink
Referenced #2513
Browse files Browse the repository at this point in the history
  • Loading branch information
MakeilaLundy committed Mar 7, 2018
1 parent aaaf324 commit 902f9b7
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/controllers/EntriesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use craft\events\ElementEvent;
use craft\helpers\DateTimeHelper;
use craft\helpers\Json;
use craft\helpers\StringHelper;
use craft\helpers\UrlHelper;
use craft\models\EntryDraft;
use craft\models\EntryVersion;
Expand Down Expand Up @@ -531,6 +532,13 @@ public function actionSaveEntry()
$revisionsService->saveVersion($currentEntry);
}

// Validate that the title does not have an emoji
if (StringHelper::hasMb4($entry->title)) {
Craft::$app->getSession()->setError(Craft::t('app', 'Couldn’t save entry with emoji in title.'));
return null;
}


// Save the entry (finally!)
if ($entry->enabled && $entry->enabledForSite) {
$entry->setScenario(Element::SCENARIO_LIVE);
Expand Down
11 changes: 11 additions & 0 deletions src/helpers/StringHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -965,6 +965,17 @@ public static function encoding(string $string): string
return static::toLowerCase(mb_detect_encoding($string, mb_detect_order(), true));
}

/**
* Detects whether the given string has any 4-byte UTF-8 characters.
*
* @param string $string
* @return bool
*/
public static function hasMb4(string $string): bool
{
return max(array_map('ord', str_split($string))) >= 240;
}

/**
* HTML-encodes any 4-byte UTF-8 characters.
*
Expand Down

0 comments on commit 902f9b7

Please sign in to comment.