Permalink
Browse files

fix(i18n): validate the translation key

If the translation key isn't a string this caused PHP warnings, so now
let the user know that the function was called incorrectly.

fixes #9673
  • Loading branch information...
jeabakker committed Sep 23, 2016
1 parent cbec2c1 commit 76d7ac69b5932f526dca1b02fb2882701369f118
Showing with 8 additions and 1 deletion.
  1. +8 −1 engine/classes/Elgg/I18n/Translator.php
@@ -40,7 +40,14 @@ public function __construct() {
public function translate($message_key, $args = [], $language = "") {
// TODO find a way to cache getLanguage() and get rid of this
static $CURRENT_LANGUAGE;
-
+
+ if (!is_string($message_key) || strlen($message_key) < 1) {
+ _elgg_services()->logger->warn(
+ '$message_key needs to be a string in ' . __METHOD__ . '(), ' . gettype($message_key) . ' provided'
+ );
+ return '';
+ }
+
// old param order is deprecated
if (!is_array($args)) {
elgg_deprecated_notice(

0 comments on commit 76d7ac6

Please sign in to comment.