Download & Extend

htmlspecialchars() warning

Project:MailChimp
Version:6.x-2.x-dev
Component:General
Category:bug report
Priority:critical
Assigned:Unassigned
Status:active

Issue Summary

admin/settings/mailchimp

When I select any role other than anonymous user, eg (authenticated user), and click , I am presented with the folowing error a number of times:

warning: htmlspecialchars() expects parameter 1 to be string, array given in /home/username/public_html/cms/includes/bootstrap.inc on line 840.

Everything appears to function correctly, but this error will appear until I deselect authenticated user, etc and save.

It also appears in release 6.x-2.0-rc4

Comments

#1

Status:active» closed (fixed)

Sorry, but I can't replicate this error on a fresh install of the latest version of Drupal, with either RC4 or the dev release, and no one else has reported it. Perhaps a conflict with another module?

#2

the update to rc5 solved the error messages

#3

Priority:normal» critical

I have just updated to Drupal 6.17 and now I have the same warning as waynemichel had. Can someone help?

#4

#5

Another proposed solution here: http://drupal.org/node/800600. Tried it because I never had issues in 6.16 when I first upgraded. But upgrading to 6.17 was the first time we had our caching settings a bit more optimized. Not sure if it will work - I'll report an update on the thread I just indicated.

UPDATE:

Didn't work - error still occurs. :s

#6

mailchimp-6.x-2.0-rc5 works, but mailchimp-6.x-2.0 breaks again.

#7

Status:closed (fixed)» active

#8

Status:active» postponed (maintainer needs more info)

wayne, please add debug code to bootstrap.inc in check_plain()

<?php
function check_plain($text) {
  static
$php525;

// add these lines
if ( is_array($text) ) {
 
$debug = 'Err - array is not a string:'. print_r($text,1) ;
// if you're on a dev site, you can uncomment next line to debug live
//  drupal_set_message($debug);
// or if on a live site you can use this to debug via watchdog (both is fine)
 
watchdog('php', $debug);
}
// addition ends, leave check_plain() as is otherwise

?>

That will show what's getting fed to check_plain() that isn't suitable.

Post the result here - you may need to debug further to identify the origin of the offending array.

#9

subscribe

#10

Version:6.x-2.x-dev» 6.x-2.0
Status:postponed (maintainer needs more info)» active

output from log file after adding the code:

htmlspecialchars() expects parameter 1 to be string, array given in /home/chs90122/public_html/cms/includes/bootstrap.inc on line 867.

Err - array is not a string:Array ( )

#11

Oh, an empty array isn't so helpful is it? Sorry Wayne - a bit more debugging to do then.

Try this and see if you can capture more info this time -

<?php
function check_plain($text) {
  static
$php525;

// add these lines
if ( is_array($text) ) {
 
$bt = debug_backtrace();
 
$debug = 'Err - array is not a string:'. print_r($text, 1) ;
 
$debug .= "\nBacktrace:\n". print_r($bt, 1);
// if you're on a dev site, you can uncomment next line to debug live
//  drupal_set_message($debug);
// or if on a live site you can use this to debug via watchdog (both is fine)
 
watchdog('php', $debug);
}
// addition ends, leave check_plain() as is otherwise

?>

That will spit out a lot of debug info, which should allow us to see what hooks/functions are feeding the incorrect array() into check_plain().

Please do the following -

0. Make sure the debug code I've posted leaves you with a working site first. check_plain() is used often enough that hitting your front page should reveal if there's an error.

1. Gather your backtrace info by triggering the error.

2. Search the backtrace for private info before posting. Eg, search for your database login and password and obscure any such 'private' details first.

3. Rather than pasting the backtrace here in entirety, post your backtrace on http://drupalbin.com/ then link to it from your comment here. The backtrace will be long, and the notification email will be ugly and mostly unhelpful to other people on this thread.

Thanks!

PS. You changed from 6.x-2.x-dev to 6.x-2.0 - does this issue not occur on 2.x-dev?

#12

Status:active» fixed

Hey gang - Finally fixed in the 6.x-2.x branch. It was definitely due to the introduction of hidden "groups" from MC. They are now filtered out.

#13

Status:fixed» closed (fixed)

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

#14

Version:6.x-2.0» 6.x-2.5

Hi levelos,

This issue seems still happens in v2.5

Warning: htmlspecialchars() expects parameter 1 to be string, array given in check_plain() (line 1152 of /srv/www/test/public_html/includes/bootstrap.inc).

#15

Component:Code» General

subscribe

#16

subscribe

#17

Version:6.x-2.5» 6.x-2.x-dev
Status:closed (fixed)» active

Seeing a lot of these errors using 6.x-2.6 and also when trying the latest 6.x-2.x-dev (2011-Oct-04).

warning: htmlspecialchars() expects parameter 1 to be string, array given in /public_html/includes/bootstrap.inc on line 865.

Adding some debug code to includes/bootstrap.inc about line 848

function check_plain($text) {
  static $php525;

  if (!isset($php525)) {
    $php525 = version_compare(PHP_VERSION, '5.2.5', '>=');
  }
  // We duplicate the preg_match() to validate strings as UTF-8 from
  // drupal_validate_utf8() here. This avoids the overhead of an additional
  // function call, since check_plain() may be called hundreds of times during
  // a request. For PHP 5.2.5+, this check for valid UTF-8 should be handled
  // internally by PHP in htmlspecialchars().
  // @see http://www.php.net/releases/5_2_5.php
  // @todo remove this when support for either IE6 or PHP < 5.2.5 is dropped.

  if ($php525) {
   if (is_array($text)) {
      vsm_trace();
      dpm($text);             
    }                         

    return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
  }
  return (preg_match('/^./us', $text) == 1) ? htmlspecialchars($text, ENT_QUOTES, 'UTF-8') : '';
}

Results in this track back which indicates a problem in Mailchimp.

form.inc: check_plain line 1553
theme.inc: call_user_func_array line 668
common.inc: theme line 2986
common.inc: drupal_render line 2976
common.inc: drupal_render line 2976
common.inc: drupal_render line 2976
common.inc: drupal_render line 2976
form.inc: drupal_render line 616
form.inc: drupal_render_form line 148
mailchimp.module: drupal_get_form line 1094
module.inc: call_user_func_array line 461
context_reaction_block.inc: module_invoke line 352
context_reaction_block.inc: context_reaction_block->build_block line 299
context_reaction_block.inc: context_reaction_block->block_list line 220
context.core.inc: context_reaction_block->execute line 225
template.php: context_blocks line 370
theme.inc: call_user_func_array line 668
theme.inc: theme line 1835
theme.inc: call_user_func_array line 709
index.php: theme line 35

    ... (Array, 0 elements)
    Krumo version 0.2a
    | http://krumo.sourceforge.net
    Called from /public_html/includes/bootstrap.inc, line 862