diff --git a/core/lib/Drupal/Component/Utility/PlaceholderTrait.php b/core/lib/Drupal/Component/Utility/PlaceholderTrait.php index 2d4c51e..b953012 100644 --- a/core/lib/Drupal/Component/Utility/PlaceholderTrait.php +++ b/core/lib/Drupal/Component/Utility/PlaceholderTrait.php @@ -104,6 +104,11 @@ protected static function placeholderFormat($string, array $args, &$safe = TRUE) if (!SafeMarkup::isSafe($value)) { $safe = FALSE; } + break; + + default: + throw new \InvalidArgumentException("Invalid placeholder"); + break; } } return strtr($string, $args); diff --git a/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php b/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php index 12f2012..842163b 100644 --- a/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php +++ b/core/tests/Drupal/Tests/Component/Utility/SafeMarkupTest.php @@ -192,6 +192,18 @@ function providerCheckPlain() { } /** + * String formatting with SafeMarkup::format() and a random placeholder. + * + * When you call SafeMarkup::format() with a random placeholder, an + * InvalidArgumentException should be thrown. + * + * @expectedException \InvalidArgumentException + */ + public function testUnexpectedFormat() { + SafeMarkup::format('Broken placeholder: ~placeholder', ['~placeholder' => 'broken'])->__toString(); + } + + /** * Tests string formatting with SafeMarkup::format(). * * @dataProvider providerFormat