This warning appear when i save any translation

Comments

Riki72 created an issue. See original summary.

kris77’s picture

I have the same issue...

Anonymous’s picture

Maybe related:
When saving a view translation I get
Warning: addcslashes() expects parameter 1 to be string, array given in DatabaseConnection->escapeLike() (regel 1007 van /home/dev/domains/.....path....../includes/database/database.inc).

antims’s picture

Me too.

maxmendez’s picture

Me too.

nicofnjnu’s picture

Same issue here.

Warning: addcslashes() expects parameter 1 to be string, array given in DatabaseConnection->escapeLike()

marinex’s picture

Me too!!!

amirma’s picture

Subscribe!

Anonymous’s picture

I'm facing this too.
I've been trying to find the problem for a while now and so far it looks like the error from title

Warning: addcslashes() expects parameter 1 to be string, array given in DatabaseConnection->escapeLike() (regel 1007 van /home/dev/domains/.....path....../includes/database/database.inc).

is different than the error that breaks the site from the parts where translated view is used.

Second error comes from entity.wrapper.inc line 760~

/**
   * Overridden to support setting the entity by either the object or the id.
   */
  public function set($value) {
    if (!$this->validate($value)) {.....

where empty value is pushed to function and validation fails. One can comment out the 'throw new...' and everything works but this doesn't fix the problem.

If somebody who knows more how this system works could give a hint from where these functions are called (DB queries to find the translation I presume), I can try to search for a solution.

Anonymous’s picture

StatusFileSize
new665 bytes

Okay, after a day well spent this patch is what I came up with.

This might introduce problems with security if malicious user has translate privileges. (I'm not sure. Maintainer, please have a look)

BUT...

If I understood correctly the function save_string($string, $keys = array(), $format = '') with the I18N_STRING_FILTER_XSS_ADMIN doesn't allow saving the translation with any malicious code and the function translate_string($string, $keys = array(), $format = '') { modified in the patch just does the printing of the strings (strings that should be secure as the save_string already checked that??)

Edit.
In my project this removes the error introduced in the title and also the error from entity.wrapper 'The website encountered an unexpected error. please try again later' that was breaking practically the whole site.

I translated few lines and got the error again, It's one huge array printed to the list of translateable view names. Tried dpm() the array and it crashed the browser.

Anonymous’s picture

Status: Active » Needs review
tankeroo’s picture

I have the same issue! following and will apply patch once maintainer approves.

anybody’s picture

Same problem here!

sano’s picture

Status: Needs review » Needs work

... applied the patch and tried to translate a string. Upon saving the translation I see the same error; so no change here.

maxmendez’s picture

I've tested the patch #10 an it does not fixed the problem, so i've debugged from escapeLike using debug_backtrace and detects that i18nviews_translate_page_form was calling views_invalidate_cache as a submit function.

This is a bad implementation of views_invalidate_cache because it will received incorrect parameter (https://api.drupal.org/api/views/views.module/function/views_invalidate_...).

I've created a custom submit function to call views_invalidate_cache without parameter and the problem disapeared.

anrikun’s picture

Version: 7.x-3.0-alpha1 » 7.x-3.x-dev
Status: Needs work » Needs review
anrikun’s picture

Status: Needs review » Reviewed & tested by the community

Path at #15 works for me.

poker10’s picture

Assigned: Riki72 » Unassigned
Issue tags: +PHP 8.1

This throws an error on PHP 8.1:

TypeError: addcslashes(): Argument #1 ($string) must be of type string, array given in addcslashes() (line 1054 in /includes/database/database.inc).

After applying the patch #15 the error is gone.

nedjo’s picture

Thanks for reporting this issue and submitting a patch.

Confirming that the patch at #15 correctly addresses what is clearly an error in the code. Nice!

More specifically:

  • Currently, in i18nviews_translate_page_form(), views_invalidate_cache() is registered as a form submit handler.
  • The first argument passed to a form submit callback is a form array.
  • However, the first argument to views_invalidate_cache() is an optional cache ID string, with a default value provided. As a result, an invalid value (a form array) is passed in.
  • The proposed fix - register a new form submit callback and, from there, call views_invalidate_cache() - correctly addresses this error.

Exactly how does this fix relate to the reported error? That's a bit more involved. Here are the specific steps:

  1. When invoked as a form submit callback, views_invalidate_cache() calls cache_clear_all($cid), feeding the form array as $cid.
  2. cache_clear_all() loads a database cache object and calls its ::clear() method return _cache_get_object($bin)->clear($cid, $wildcard);
  3. ::clear() method calls db_like() as part of generating an argument value: db_delete($this->bin)->condition('cid', db_like($cid) . '%', 'LIKE')->execute();
  4. db_like() calls the database connection object's ::escapeLike() method.
  5. The ::escapeLike() method calls addslashes(), feeding an array rather than a string, and thus triggers the error.

Nitpick: it would be nice to have a "docblock" for the new form submit callback.

  • nedjo committed 25486536 on 7.x-3.x authored by MaxMendez
    Issue #2975245 by MaxMendez: Warning: addcslashes() expects parameter 1...
nedjo’s picture

Status: Reviewed & tested by the community » Fixed

Thx, applied.

Status: Fixed » Closed (fixed)

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