Problem/Motivation

The bang ("!") placeholder for t() and format() has been removed in https://www.drupal.org/node/2575819 as a consequence of #2506427: [meta] !placeholder causes strings to be escaped and makes the sanitization API harder to understand, but LogMessageParser::parseMessagePlaceholders() still accepts it and does not accept the new colon (":") placeholder for URLs.

Note: I put this in the dblog component because there's currently no logger subsystem defined in the issue queue, but there should probably be one (which I'd volunteer to maintain, BTW).

Steps to reproduce

Proposed resolution

The line reading:
if (!empty($key) && ($key[0] === '@' || $key[0] === '%' || $key[0] === '!')) {

should probably read
if (!empty($key) && ($key[0] === '@' || $key[0] === '%' || $key[0] === ':')) {

instead.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

fgm created an issue. See original summary.

fgm’s picture

Status: Active » Needs review
FileSize
696 bytes

Let's see what the existing tests says.

dawehner’s picture

Issue tags: +Needs tests
+++ b/core/lib/Drupal/Core/Logger/LogMessageParser.php
@@ -34,7 +34,7 @@ public function parseMessagePlaceholders(&$message, array &$context) {
       }
-      if (!empty($key) && ($key[0] === '@' || $key[0] === '%' || $key[0] === '!')) {
+      if (!empty($key) && ($key[0] === '@' || $key[0] === '%' || $key[0] === ':')) {
         // The key is now in \Drupal\Component\Utility\SafeMarkup::format() style.

Right, other ones would pass then to t() in Dblog, which is IMHO still crazy, but we do that.

Some simple test would be nice!

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dagmar’s picture

#2481349: Prevent the use of placeholders that cannot be converted into strings when creating logs here we have tests for this, test are not passing at this moment. Can we set this to duplicate and work on the other issue?

dawehner’s picture

@dagmar
I'm a bit confused because this fix doesn't appear in the issue you linked to.

dagmar’s picture

@dawehner Please take a look to comment #23 https://www.drupal.org/node/2481349#comment-10905482 and #27

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

guedressel’s picture

Title: LogMessageParser::parseMessagePlaceholders() needs to remove bang placeholder » LogMessageParser::parseMessagePlaceholders() needs to switch bang placeholder to colon placeholder

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

dagmar’s picture

Status: Needs review » Needs work

This still needs tests.

dagmar’s picture

Status: Needs work » Closed (duplicate)

I'm closing this issue in favor of #2760031: Log messages won't appear translated if they have special characters in them which contains all the tests that this issue requires.

dagmar’s picture

Version: 8.3.x-dev » 9.3.x-dev
Status: Closed (duplicate) » Needs work
Issue tags: -Needs tests +Novice
FileSize
1020 bytes

This hasn't been fixed in 5 years. Let's provide a simple test that expose the issue and get someone write the patch. The patch that fixes this issue is in #2. We need to provide a combined patch with the test provided here and the fix provided in #2.

dagmar’s picture

Status: Needs work » Needs review
FileSize
1022 bytes

Fixed some typos in the comment.

dagmar’s picture

More typos...

Status: Needs review » Needs work

The last submitted patch, 15: 2617330-15.patch, failed testing. View results

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mfb’s picture

Status: Needs work » Needs review
FileSize
1.68 KB
576 bytes

I finally just stumbled into this bug, after noticing that two of my logger modules are not parsing message placeholders correctly (of course it also affects dblog and syslog modules).

Combining the test patch from #15 with the bug fix patch from #2

mfb’s picture

Issue summary: View changes
Status: Needs review » Reviewed & tested by the community

I tested the patch with dblog, Drush logger and two contrib loggers; log messages with <a href=":url"> now render correctly :) Marking this RTBC since I didn't write either parts of the patch; also fixing a typo in the issue summary.

quietone’s picture

Issue summary: View changes

Just added template to the IS.

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/tests/Drupal/Tests/Core/Logger/LogMessageParserTest.php
@@ -63,6 +63,11 @@ public function providerTestParseMessagePlaceholders() {
+      // Message with :placeholder and !placeholder now removed.

This is not very clear. :placeholder is not removed.

I think it is okay to just remove the ! - I'm not sure that we need to support : - maybe it is best for consistency but we've survived this long without it...

I think this should read something like
// Test removal unexpected placeholders like ! while allowed placeholders beginning with @, % and : are preserved.

Ratan Priya’s picture

Status: Needs work » Needs review
FileSize
1.74 KB
1.09 KB

@alexpott,
Made changes as per comment #22.
Needs review.

mfb’s picture

@Ratan Priya can you wrap the long comment onto multiple lines at 80 characters? Also, the grammar is off - should be

Test removal of unexpected placeholders
fgm’s picture

Probably off-topic, but it seems that Ratan rerunning the tests for my path removed credit for my creating it in the first place. Looks like a bug in drupal.org, does it not ?

hestenet’s picture

@fgm - likely a bug introduced by: #3226881: Do not automatically credit people who upload files to an issue - we'll investigate

alexpott’s picture

Crediting @fgm

alexpott’s picture

+++ b/core/tests/Drupal/Tests/Core/Logger/LogMessageParserTest.php
@@ -63,6 +63,11 @@ public function providerTestParseMessagePlaceholders() {
+      // Test removal unexpected placeholders like ! while allowed placeholders beginning with @, % and : are preserved.
+      [

The comment should wrap at 80 characters. I will fix this if this patch is rtbc.

drumm’s picture

@fgm - credit is not saved until a maintainer comments. They may update as they go, and should decide on final credit as the issue is fixed, credit is not complete until the issue is fixed. In this case, you were indeed first credited by #27. Maintainers had commented previously, so they did not choose to credit at the time. This could have been an explicit decision, or could have been the defaults at the time did not suggest crediting people who uploaded patches. Since this was seven years ago, and the system worked as alexpott has credited you, this is not worth spending any more time investigating.

dagmar’s picture

Status: Needs review » Needs work

Needs work per #24 . This requires a minor grammar fix, and wrap the comment to 80 characters.

pradhumanjain2311’s picture

Assigned: Unassigned » pradhumanjain2311
pradhumanjain2311’s picture

Title: LogMessageParser::parseMessagePlaceholders() needs to switch bang placeholder to colon placeholder » LogMesshttps://www.drupal.org/u/dagmarageParser::parseMessagePlaceholders() needs to switch bang placeholder to colon placeholder
Assigned: pradhumanjain2311 » Unassigned
Status: Needs work » Needs review
FileSize
1.77 KB
1.18 KB

@dagmar i made changes as per comment #24 needs review.

fgm’s picture

Title: LogMesshttps://www.drupal.org/u/dagmarageParser::parseMessagePlaceholders() needs to switch bang placeholder to colon placeholder » LogMessageParser::parseMessagePlaceholders() needs to switch bang placeholder to colon placeholder

Restored title damaged by previous comment.

dagmar’s picture

Status: Needs review » Reviewed & tested by the community

Thanks @pradhumanjainOSL According to https://www.drupal.org/docs/develop/standards/api-documentation-and-comm... use of /* */ comments is ok but discouraged within functions.

Maybe @alexpott wants to fix that as he mentioned in #28

Anyways this looks good.

  • alexpott committed c58a486 on 10.1.x
    Issue #2617330 by dagmar, mfb, pradhumanjainOSL, Ratan Priya, fgm,...

  • alexpott committed fcf7e66 on 10.0.x
    Issue #2617330 by dagmar, mfb, pradhumanjainOSL, Ratan Priya, fgm,...
alexpott’s picture

Status: Reviewed & tested by the community » Fixed

Backported to 9.5.x as a low risk bug fix. Thanks!

diff --git a/core/tests/Drupal/Tests/Core/Logger/LogMessageParserTest.php b/core/tests/Drupal/Tests/Core/Logger/LogMessageParserTest.php
index 13cb673155..8d1347bc57 100644
--- a/core/tests/Drupal/Tests/Core/Logger/LogMessageParserTest.php
+++ b/core/tests/Drupal/Tests/Core/Logger/LogMessageParserTest.php
@@ -63,10 +63,9 @@ public function providerTestParseMessagePlaceholders() {
         ['message' => 'Test {with} two {{encapsuled}} strings', 'context' => ['with' => 'together', 'encapsuled' => 'awesome']],
         ['message' => 'Test @with two {@encapsuled} strings', 'context' => ['@with' => 'together', '@encapsuled' => 'awesome']],
       ],
-      /**
-      * Test removal of unexpected placeholders like ! while allowed placeholders
-      * beginning with @, % and : are preserved.
-      **/
+
+      // Test removal of unexpected placeholders like ! while allowed
+      // placeholders beginning with @, % and : are preserved.
       [
         ['message' => 'Test placeholder with :url and old !bang parameter', 'context' => [':url' => 'https://drupal.org', '!bang' => 'foo bar']],
         ['message' => 'Test placeholder with :url and old !bang parameter', 'context' => [':url' => 'https://drupal.org']],

Fixed code comments on commit.

  • alexpott committed 6510e5e on 9.5.x
    Issue #2617330 by dagmar, mfb, pradhumanjainOSL, Ratan Priya, fgm,...
alexpott’s picture

Version: 9.5.x-dev » 9.4.x-dev

Discussed with @longwave we agreed to backport this to 9.4.x

Committed 59143d8 and pushed to 9.4.x. Thanks!

  • alexpott committed 59143d8 on 9.4.x
    Issue #2617330 by dagmar, mfb, pradhumanjainOSL, Ratan Priya, fgm,...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.