I attached 6 links to a new piece of content. When I clicked preview, I received this error 6 times. I did not interfere with me saving the content, and the preview looked ok, but I did not click the links in the preview for fear of losing my content. I cut of the error in the title field. Here is the full error with my directory structure omitted.

Warning: unserialize() expects parameter 1 to be string, array given in _link_load() (line 262 of /var/www/.../modules/link/link.module).

CommentFileSizeAuthor
#10 link-always-serialize-1242168-10.patch590 bytesbcn

Comments

ldw-1’s picture

Issue summary: View changes

Warning: unserialize() expects parameter 1 to be string, array given in _link_load() (line 262 of /var/www/.../modules/link/link.module).

Pocketpain’s picture

Same...sub

Pallie’s picture

Changing:

return unserialize($item['attributes']);

Into:

return $item['attributes'];

in the _link_load() function on line 262 in the link.module file, seems to fix this issue, and I can't find any impact on other things by removing the unserialize() call...

dqd’s picture

Status: Active » Fixed

Please use latest --dev and re-test! Many known issues are fixed in latest --dev.
If the error still occurs, please come back to report on a new issue for latest --dev since we push for the coming beta release.

Your reports are much appreciated! thank you!

bcn’s picture

Version: 7.x-1.0-alpha3 » 7.x-1.x-dev
Status: Fixed » Active

While testing with the latest dev release I got:
Warning: unserialize() expects parameter 1 to be string, array given in _link_load() line 292...

The change mentioned by Pallie does remove the warning, but I am also unsure if that's the correct fix.

dqd’s picture

okay. do we have #2 committed? not sure. I will check it this night (CET)

bcn’s picture

code from #2 has not been committed, but I it would be wise to make sure there are not some side effects to removing the unserialize, as suggested.

dqd’s picture

noahb, thanks 4 info. I am stil not sure if this is the right point to patch, since I had some other commits to run last days and calling unserialize() will surely have its reason here.

dankobiaka’s picture

The issue seems to lie with the code that is doing the serializing.
By testing if the variable is not a string before serializing, this results in string values being stored as plain text - therefore causing an error when trying to unserialize.

To resolve the issue, _link_process() needs to be coded to always serialize $item['attributes']

/**
 * Prepares the item attributes and url for storage.
 */
function _link_process(&$item, $delta = 0, $field, $entity) {
  // Trim whitespace from URL.
  $item['url'] = trim($item['url']);

  // if no attributes are set then make sure $item['attributes'] is an empty array - this lets $field['attributes'] override it.
  if (empty($item['attributes'])) {
    $item['attributes'] = array();
  }

  // Serialize the attributes array.
  $item['attributes'] = serialize($item['attributes']);

  // Don't save an invalid default value (e.g. 'http://').
  if ((isset($field['widget']['default_value'][$delta]['url']) && $item['url'] == $field['widget']['default_value'][$delta]['url'])
      && is_object($node)) {
    if (!link_validate_url($item['url'])) {
      unset($item['url']);
    }
  }
}
dqd’s picture

#dankobiaka, thanks for trying to help. Can you please provide a patch. It is better for understanding the code change, where the change is made, better for the flow (forth and back versioning) and can be easier committed with your credits to the repo.

bcn’s picture

Status: Active » Needs review
StatusFileSize
new590 bytes

patch from #8

dankobiaka’s picture

The issue with attributes seems to be even more serious.

It appears as though _link_sanitize() is being called on node insertion, resulting in the attributes array being unserialized before getting written to the database. This is causing a fatal SQL error.

In those cases, link_field_prepare_view() is getting called on node insertion BEFORE the field is written to SQL storage.
The error is not occurring in all cases for me and I'm not quite sure what to tell you in order to reproduce it (I have multiple link fields on the node).

I am using Drupal 7.9 and Link 7.x-1.x-dev.

See my comment at http://drupal.org/node/1290904#comment-5173082

minhtao’s picture

subscribe

ladybug_3777’s picture

Still waiting for a resolution for this issue. Wanted to comment so that it's still seen as an open problem.

p5B0EODLAElkqmSm’s picture

subscribe

p5B0EODLAElkqmSm’s picture

Issue summary: View changes

Added the directory structure included in the error message.

chris matthews’s picture

Issue summary: View changes
Status: Needs review » Needs work
Issue tags: +Needs reroll

The 7 year old patch in #10 to link.module does not apply to the latest link 7.x-1.x-dev and if still applicable needs a reroll.

Checking patch link.module...
error: while searching for:
  }

  // Serialize the attributes array.
  if (!is_string($item['attributes'])) {
    $item['attributes'] = serialize($item['attributes']);
  }

  // Don't save an invalid default value (e.g. 'http://').
  if ((isset($field['widget']['default_value'][$delta]['url']) && $item['url'] == $field['widget']['default_value'][$delta]['url'])

error: patch failed: link.module:335
error: link.module: patch does not apply