diff --git a/core/modules/dblog/src/Controller/DbLogController.php b/core/modules/dblog/src/Controller/DbLogController.php index 5b1ec80e478..c61e5016660 100644 --- a/core/modules/dblog/src/Controller/DbLogController.php +++ b/core/modules/dblog/src/Controller/DbLogController.php @@ -2,6 +2,7 @@ namespace Drupal\dblog\Controller; +use Drupal\Component\Render\FormattableMarkup; use Drupal\Component\Utility\Html; use Drupal\Component\Utility\Unicode; use Drupal\Component\Utility\Xss; @@ -362,6 +363,12 @@ class DbLogController extends ControllerBase { } // Message to translate with injected variables. else { + // Ensure backtrace strings are properly formatted. + if (isset($variables['@backtrace_string'])) { + $variables['@backtrace_string'] = new FormattableMarkup( + '
@backtrace_string', $variables + ); + } $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 d12f88b1a1e..9f7475b82db 100644 --- a/core/modules/dblog/tests/src/Functional/DbLogTest.php +++ b/core/modules/dblog/tests/src/Functional/DbLogTest.php @@ -10,6 +10,7 @@ use Drupal\Core\Logger\RfcLogLevel; use Drupal\Core\Link; use Drupal\Core\Url; use Drupal\dblog\Controller\DbLogController; +use Drupal\error_test\Controller\ErrorTestController; use Drupal\Tests\BrowserTestBase; /** @@ -26,7 +27,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', + ]; /** * {@inheritdoc} @@ -793,4 +801,28 @@ class DbLogTest extends BrowserTestBase { $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' => ErrorTestController::class . '->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('
'); + } + }