Heine

  • home
  • drupal
  • drupal core commits
  • about
Home › Drupal Core Commits

Commit 336422 by dries

- Patch #353918 by Dave Reid, yched: drupal_write_record() writes empty string instead of empty serialized array.

--- <a href="http://drupalcode.org/viewvc/drupal/drupal/includes/common.inc" title="http://drupalcode.org/viewvc/drupal/drupal/includes/common.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/includes/common.inc</a>   2010/03/02 08:47:41     1.1118
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/includes/common.inc" title="http://drupalcode.org/viewvc/drupal/drupal/includes/common.inc" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/includes/common.inc</a>   2010/03/03 08:40:25     1.1119
@@ -5741,7 +5741,7 @@
     if (empty($info['serialize'])) {
       $fields[$field] = $object->$field;
     }
-    elseif (!empty($object->$field)) {
+    elseif (isset($object->$field)) {
       $fields[$field] = serialize($object->$field);
     }
     else {

--- <a href="http://drupalcode.org/viewvc/drupal/drupal/modules/simpletest/tests/common.test" title="http://drupalcode.org/viewvc/drupal/drupal/modules/simpletest/tests/common.test" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/modules/simpletest/tests/comm...</a>    2010/03/02 08:47:41     1.104
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/modules/simpletest/tests/common.test" title="http://drupalcode.org/viewvc/drupal/drupal/modules/simpletest/tests/common.test" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/modules/simpletest/tests/comm...</a>    2010/03/03 08:40:25     1.105
@@ -1561,6 +1561,26 @@
     $this->assertIdentical($result->name, 'Mary', t('Name field set.'));
     $this->assertIdentical($result->age, NULL, t('Age field set.'));
 
+    // Insert a record - the "data" column should be serialized.
+    $person = new stdClass();
+    $person->name = 'Dave';
+    $update_result = drupal_write_record('test_serialized', $person);
+    $result = db_query("SELECT * FROM {test_serialized} WHERE id = :id", array(':id' => $person->id))->fetchObject();
+    $this->assertIdentical($result->name, 'Dave', t('Name field set.'));
+    $this->assertIdentical($result->info, NULL, t('Info field set.'));
+
+    $person->info = array();
+    $update_result = drupal_write_record('test_serialized', $person, array('id'));
+    $result = db_query("SELECT * FROM {test_serialized} WHERE id = :id", array(':id' => $person->id))->fetchObject();
+    $this->assertIdentical(unserialize($result->info), array(), t('Info field updated.'));
+
+    // Update the serialized record.
+    $data = array('foo' => 'bar', 1 => 2, 'empty' => '', 'null' => NULL);
+    $person->info = $data;
+    $update_result = drupal_write_record('test_serialized', $person, array('id'));
+    $result = db_query("SELECT * FROM {test_serialized} WHERE id = :id", array(':id' => $person->id))->fetchObject();
+    $this->assertIdentical(unserialize($result->info), $data, t('Info field updated.'));
+
     // Run an update query where no field values are changed. The database
     // layer should return zero for number of affected rows, but
     // db_write_record() should still return SAVED_UPDATED.

--- <a href="http://drupalcode.org/viewvc/drupal/drupal/modules/simpletest/tests/database_test.install" title="http://drupalcode.org/viewvc/drupal/drupal/modules/simpletest/tests/database_test.install" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/modules/simpletest/tests/data...</a>        2009/12/04 16:49:47     1.10
+++ <a href="http://drupalcode.org/viewvc/drupal/drupal/modules/simpletest/tests/database_test.install" title="http://drupalcode.org/viewvc/drupal/drupal/modules/simpletest/tests/database_test.install" rel="nofollow">http://drupalcode.org/viewvc/drupal/drupal/modules/simpletest/tests/data...</a>        2010/03/03 08:40:25     1.11
@@ -35,7 +35,8 @@
         'type' => 'int',
         'unsigned' => TRUE,
         'not null' => TRUE,
-        'default' => 0),
+        'default' => 0,
+      ),
       'job' => array(
         'description' => "The person's job",
         'type' => 'varchar',
@@ -202,5 +203,32 @@
     ),
   );
 
+  $schema['test_serialized'] = array(
+    'description' => 'Basic test table for NULL value handling.',
+    'fields' => array(
+      'id' => array(
+        'type' => 'serial',
+        'unsigned' => TRUE,
+        'not null' => TRUE,
+      ),
+      'name' => array(
+        'description' => "A person's name.",
+        'type' => 'varchar',
+        'length' => 255,
+        'not null' => FALSE,
+        'default' => '',
+      ),
+      'info' => array(
+        'description' => "The person's data in serialized form.",
+        'type' => 'text',
+        'serialize' => TRUE,
+      ),
+    ),
+    'primary key' => array('id'),
+    'unique keys' => array(
+      'name' => array('name')
+    ),
+  );
+
   return $schema;
 }

No votes yet
  • Drupal Core
  • Download patch

Recent posts

  • The Joomlafication of the Dutch-speaking community
  • Upgraded from 6.14 to 6.15, but Drupal still thinks it's 6.14?
  • Google Friendconnect Drupal module not recommended (yet)
  • The OpenID 2.0 Compliance Crusade - Part I
  • Using <embed> for XSS
more

Security reviews

  • Afraid custom code makes your site vulnerable?
  • You don't really trust that module you just downloaded from Drupal.org?

Sleep better after a security review.

Tags

Captcha CSRF DOH! Drupal embed Input Format modx OpenID Performance Planet Drupal Security Varnish
more tags
  • home
  • drupal
  • drupal core commits
  • about

Copyright © 2010 by Heine Deelstra. All rights reserved.