summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLee Rowlands2018-01-03 21:14:47 (GMT)
committerLee Rowlands2018-01-03 21:14:47 (GMT)
commit72c76b73c5c9a7ae42f288e86191464fe4a6ee39 (patch)
treeef83e604b592746ee27b39731250b28d51610c3b
parent354462c6f6fb7407d1ef319d49d9fba72e5e0e5d (diff)
Issue #2359389 by harsha012, hgoto, jeqq, fago, sureshcj, larowlan: Call to a member function filters() on a non-object in core/modules/text/text.module on line 83
-rw-r--r--core/modules/text/tests/src/Kernel/TextSummaryTest.php9
-rw-r--r--core/modules/text/text.module4
2 files changed, 11 insertions, 2 deletions
diff --git a/core/modules/text/tests/src/Kernel/TextSummaryTest.php b/core/modules/text/tests/src/Kernel/TextSummaryTest.php
index dab6ed5..2eeaf2d 100644
--- a/core/modules/text/tests/src/Kernel/TextSummaryTest.php
+++ b/core/modules/text/tests/src/Kernel/TextSummaryTest.php
@@ -208,6 +208,15 @@ class TextSummaryTest extends KernelTestBase {
}
/**
+ * 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.
*/
public function assertTextSummary($text, $expected, $format = NULL, $size = NULL) {
diff --git a/core/modules/text/text.module b/core/modules/text/text.module
index 1932e61..b88fdc1 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 '';
}
}