Problem/Motivation

When attempting to log a spam form submission, the form_id is missing from the message and the error "Warning: htmlspecialchars() expects parameter 1 to be string, array given in Drupal\Component\Utility\Html::escape() (line 424 of C:\wamp64\www\d8\web\core\lib\Drupal\Component\Utility\Html.php)" is generated.

Steps to reproduce

Enable logging. Use a browser tool to display the feed_me input element, add data to it, and submit it. Observe that the logged message is missing the form_id and the addition

Proposed resolution

In spamicide.module, spamicide_validate calls:

    \Drupal::logger('spamicide')->notice(
      t('%form_id post blocked by Spamicide module: their IP address is "%ipaddress".',
        [
          '%form_id' => $form['form_id'],
          '%ipaddress' => Drupal::request()->getClientIp(),
        ])
    );

$form['form_id'] is a form element. What is intended is $form['#form_id'] which is the string of the form id.

Furthermore, this isn't how messages should be logged. They should not be translated and the placeholders should be passed. The correct call should be (untested):

    \Drupal::logger('spamicide')->notice(
      '%form_id post blocked by Spamicide module: their IP address is "%ipaddress".',
      [
        '%form_id' => $form['#form_id'],
        '%ipaddress' => Drupal::request()->getClientIp(),
      ]
    );
CommentFileSizeAuthor
#2 spamicide-logger-3210110-1.patch1.07 KBdanchadwick

Issue fork spamicide-3210110

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

DanChadwick created an issue. See original summary.

danchadwick’s picture

Status: Active » Needs review
StatusFileSize
new1.07 KB

Here's a patch. Still getting comfortable with the merge request workflow.

lamp5’s picture

Status: Needs review » Needs work

I can see that you removed t() function from your fix.

danchadwick’s picture

Status: Needs work » Needs review

Correct. Logger messages, including notice() should not be translated. Search core for 'notice(' and you'll see what I mean.

  • lamp5 committed 4012707 on 8.x-1.x authored by DanChadwick
    Issue #3210110 by DanChadwick: Logging a spam attempt triggers Warning:...
lamp5’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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