diff --git a/core/modules/text/tests/src/Kernel/TextSummaryTest.php b/core/modules/text/tests/src/Kernel/TextSummaryTest.php
index dab6ed5de51e1e1f62ba37e484c6dcb32dd36dc8..2eeaf2de0be6aaf0eaae158bf6eafa3c22c89af3 100644
--- a/core/modules/text/tests/src/Kernel/TextSummaryTest.php
+++ b/core/modules/text/tests/src/Kernel/TextSummaryTest.php
@@ -207,6 +207,15 @@ public function testLength() {
$this->assertTextSummary($text, "
\nHi\n
\n\nfolks\n
\n!\n
", $format, $i++);
}
+ /**
+ * Test text_summary() returns an empty string without any error when called
+ * with an invalid format.
+ */
+ public function testInvalidFilterFormat() {
+
+ $this->assertTextSummary($this->randomString(100), '', 'non_existent_format');
+ }
+
/**
* Calls text_summary() and asserts that the expected teaser is returned.
*/
diff --git a/core/modules/text/text.module b/core/modules/text/text.module
index 1932e616496630ea4c5af480c637a4996607d3ac..b88fdc1fd74cb7fff7d2952331ef07dd80818fb4 100644
--- a/core/modules/text/text.module
+++ b/core/modules/text/text.module
@@ -81,11 +81,11 @@ function text_summary($text, $format = NULL, $size = NULL) {
// Retrieve the filters of the specified text format, if any.
if (isset($format)) {
- $filters = FilterFormat::load($format)->filters();
+ $filter_format = FilterFormat::load($format);
// If the specified format does not exist, return nothing. $text is already
// filtered text, but the remainder of this function will not be able to
// ensure a sane and secure summary.
- if (!$filters) {
+ if (!$filter_format || !($filters = $filter_format->filters())) {
return '';
}
}