Make WordPress Core

Opened 20 years ago

Closed 20 years ago

Last modified 20 years ago

#3394 closed defect (bug) (fixed)

Possible bug in update_option()

Reported by: roscohead Owned by:
Priority: normal Milestone: 2.2
Component: General Version: 2.0.5
Severity: normal Keywords: has-patch commit
Cc: Focuses:

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 (1)

functions.patch (415 bytes ) - added by Viper007Bond 20 years ago.

Download all attachments as: .zip

Change History (10)

#1 @roscohead
20 years ago

  • Version2.0.5

#2 @Viper007Bond
20 years ago

  • Milestone2.1

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

#3 @roscohead
20 years ago

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

#4 @markjaquith
20 years ago

Patch it up!

#5 @Viper007Bond
20 years ago

  • Keywords has-patch added

#6 @Viper007Bond
20 years ago

  • Keywords commit added

#7 @matt
20 years ago

  • Milestone 2.12.2

#8 @ryan
20 years ago

  • Resolutionfixed
  • Status newclosed

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

#9 @markjaquith
20 years ago

Backport candidate for 2.1.2 and 2.0.10 ?

Note: See TracTickets for help on using tickets.