Ticket #3394 (closed defect: fixed)

Opened 2 years ago

Last modified 2 years ago

Possible bug in update_option()

Reported by: roscohead Assigned to: anonymous
Priority: normal Milestone: 2.2
Component: General Version: 2.0.5
Severity: normal Keywords: has-patch commit
Cc:

Description

I posted this on the forum, and someone kindly pointed me here :)

I think I've hit a bug in the update_option() function. The problem occurs when the $newvalue is an array containing arrays - it checks

	// If the new and old values are the same, no need to update.
	$oldvalue = get_option($option_name);
	if ( $newvalue == $oldvalue ) {
		return false;
	}

to see if the value has changed. However this behaves incorrectly when the only change is in the order of elements of the sub-array, the comparison returns true, so the setting is never updated.

My workaround is to do a comparison on the serialized versions instead:

	// If the new and old values are the same, no need to update.
	$oldvalue = get_option($option_name);
	if ( maybe_serialize($newvalue) == maybe_serialize($oldvalue) ) {
		return false;
	}

This seems to work, and doesn't seem to break anything, but it has only been minimally tested. If there's a better way to fix the problem, feel free to ignore my suggested fix :)

ROSCO

Attachments

functions.patch (415 bytes) - added by Viper007Bond on 11/29/06 08:03:12.

Change History

11/26/06 20:55:55 changed by roscohead

  • version set to 2.0.5.

11/27/06 07:05:17 changed by Viper007Bond

  • milestone set to 2.1.

What about a triple equal sign (===) instead. Wouldn't that work?

11/27/06 21:09:58 changed by roscohead

D'oh! Of course it would! Thanks for that.

11/28/06 23:50:19 changed by markjaquith

Patch it up!

11/29/06 08:03:12 changed by Viper007Bond

  • attachment functions.patch added.

11/29/06 08:03:26 changed by Viper007Bond

  • keywords set to has-patch.

11/29/06 08:03:38 changed by Viper007Bond

  • keywords changed from has-patch to has-patch commit.

12/01/06 03:24:06 changed by matt

  • milestone changed from 2.1 to 2.2.

02/23/07 00:49:39 changed by ryan

  • status changed from new to closed.
  • resolution set to fixed.

(In [4920]) Use === to compare option values. Props roscohead and Viper007Bond. fixes #3394

02/25/07 11:59:54 changed by markjaquith

Backport candidate for 2.1.2 and 2.0.10 ?