diff --git a/core/modules/dblog/src/Controller/DbLogController.php b/core/modules/dblog/src/Controller/DbLogController.php index 54bc7ea..250969f 100644 --- a/core/modules/dblog/src/Controller/DbLogController.php +++ b/core/modules/dblog/src/Controller/DbLogController.php @@ -362,6 +362,10 @@ public function formatMessage($row) { } // Message to translate with injected variables. else { + // Ensure backtrace strings are properly formatted. + if ($row->message == '%type: @message in %function (line %line of %file) @backtrace_string.') { + $row->message = '%type: @message in %function (line %line of %file).
@backtrace_string
'; + } $message = $this->t(Xss::filterAdmin($row->message), $variables); } } diff --git a/core/modules/dblog/tests/src/Functional/DbLogTest.php b/core/modules/dblog/tests/src/Functional/DbLogTest.php index 7e8c3be..7f9c297 100644 --- a/core/modules/dblog/tests/src/Functional/DbLogTest.php +++ b/core/modules/dblog/tests/src/Functional/DbLogTest.php @@ -2,6 +2,7 @@ namespace Drupal\Tests\dblog\Functional; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Unicode; use Drupal\Core\Database\Database; @@ -24,7 +25,14 @@ class DbLogTest extends BrowserTestBase { * * @var array */ - public static $modules = ['dblog', 'node', 'forum', 'help', 'block']; + public static $modules = [ + 'dblog', + 'error_test', + 'node', + 'forum', + 'help', + 'block', + ]; /** * A user with some relevant administrative permissions. @@ -786,4 +794,28 @@ public function testSameTimestampEntries() { $this->assertEquals($entries[2]['message'], 'First Entry #0'); } + /** + * Tests that the details page displays correctly backtrace. + */ + public function testBacktrace() { + $this->drupalLogin($this->adminUser); + $this->drupalGet('/error-test/generate-warnings'); + + $wid = Database::getConnection()->query('SELECT MAX(wid) FROM {watchdog}')->fetchField(); + $this->drupalGet('admin/reports/dblog/event/' . $wid); + + $error_user_notice = [ + '%type' => 'User warning', + '@message' => 'Drupal & awesome', + '%function' => 'Drupal\error_test\Controller\ErrorTestController->generateWarnings()', + '%file' => drupal_get_path('module', 'error_test') . '/error_test.module', + ]; + + // Check if the full message displays on the details page and backtrace is a + // pre-formatted text. + $message = new FormattableMarkup('%type: @message in %function (line', $error_user_notice); + $this->assertRaw($message); + $this->assertRaw('
');
+  }
+
 }