diff --git src/wp-includes/option.php src/wp-includes/option.php
index 6134606..b32606c 100644
|
|
function update_option( $option, $value ) { |
264 | 264 | */ |
265 | 265 | $value = apply_filters( 'pre_update_option', $value, $option, $old_value ); |
266 | 266 | |
267 | | // If the new and old values are the same, no need to update. |
268 | | if ( $value === $old_value ) |
| 267 | /* |
| 268 | * If the new and old values are the same, no need to update. |
| 269 | * Scalar values in the cache will always be strings, so we must compare string values. |
| 270 | */ |
| 271 | if ( is_scalar( $value ) ) { |
| 272 | $_value = (string) $value; |
| 273 | } else { |
| 274 | $_value = $value; |
| 275 | } |
| 276 | |
| 277 | if ( $_value === $old_value ) |
269 | 278 | return false; |
270 | 279 | |
271 | 280 | if ( false === $old_value ) |
diff --git tests/phpunit/tests/option/option.php tests/phpunit/tests/option/option.php
index a866cea..6807afe 100644
|
|
class Tests_Option_Option extends WP_UnitTestCase { |
99 | 99 | function test_special_option_name_notoptions() { |
100 | 100 | delete_option( 'notoptions' ); |
101 | 101 | } |
| 102 | |
| 103 | /** |
| 104 | * @ticket 22192 |
| 105 | */ |
| 106 | public function test_update_option_should_fail_when_passing_an_int_that_is_loosely_equal_to_existing_option_and_option_is_in_cache() { |
| 107 | add_option( 'foo', '1' ); |
| 108 | |
| 109 | global $wpdb; |
| 110 | $num_queries = $wpdb->num_queries; |
| 111 | |
| 112 | $updated = update_option( 'foo', 1 ); |
| 113 | |
| 114 | $this->assertFalse( $updated ); |
| 115 | $this->assertSame( $num_queries, $wpdb->num_queries ); |
| 116 | $this->assertFalse( update_option( 'foo', 1 ) ); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * @ticket 22192 |
| 121 | */ |
| 122 | public function test_update_option_should_fail_when_passing_a_float_that_is_loosely_equal_to_existing_option_and_option_is_in_cache() { |
| 123 | add_option( 'foo', '1' ); |
| 124 | |
| 125 | global $wpdb; |
| 126 | $num_queries = $wpdb->num_queries; |
| 127 | |
| 128 | $updated = update_option( 'foo', floatval( 1 ) ); |
| 129 | |
| 130 | $this->assertFalse( $updated ); |
| 131 | $this->assertSame( $num_queries, $wpdb->num_queries ); |
| 132 | $this->assertFalse( update_option( 'foo', 1 ) ); |
| 133 | } |
102 | 134 | } |