@@ -161,6 +161,75 @@ public function test_serialized_data() {
161161 $ this ->assertTrue ( delete_option ( $ key ) );
162162 }
163163
164+ /**
165+ * Tests that get_option() returns the default value when stored data is corrupted/unserializable.
166+ *
167+ * @ticket 59588
168+ *
169+ * @covers ::get_option
170+ */
171+ public function test_get_option_returns_default_when_unserialize_fails () {
172+ global $ wpdb ;
173+
174+ // Insert a corrupted serialized value directly into the DB.
175+ $ option_name = 'test_corrupted_option_59588 ' ;
176+ $ wpdb ->insert (
177+ $ wpdb ->options ,
178+ array (
179+ 'option_name ' => $ option_name ,
180+ 'option_value ' => 'a:2:{i:0;s:3:"foo"; ' , // Truncated/corrupted serialized array.
181+ 'autoload ' => 'yes ' ,
182+ )
183+ );
184+ // Clear alloptions cache so get_option() reads from DB.
185+ wp_cache_delete ( 'alloptions ' , 'options ' );
186+ wp_cache_delete ( $ option_name , 'options ' );
187+
188+ $ default = array ( 'default_key ' => 'default_value ' );
189+ $ result = get_option ( $ option_name , $ default );
190+
191+ // Cleanup.
192+ $ wpdb ->delete ( $ wpdb ->options , array ( 'option_name ' => $ option_name ) );
193+ wp_cache_delete ( 'alloptions ' , 'options ' );
194+ wp_cache_delete ( $ option_name , 'options ' );
195+
196+ $ this ->assertSame ( $ default , $ result , 'get_option() should return the default value when stored data cannot be unserialized. ' );
197+ }
198+
199+ /**
200+ * Tests that get_option() correctly returns false when the stored value is a serialized boolean false.
201+ *
202+ * @ticket 59588
203+ *
204+ * @covers ::get_option
205+ */
206+ public function test_get_option_returns_false_for_serialized_false_value () {
207+ global $ wpdb ;
208+
209+ // Insert the serialization of boolean false (`b:0;`) directly into the DB.
210+ $ option_name = 'test_serialized_false_59588 ' ;
211+ $ wpdb ->insert (
212+ $ wpdb ->options ,
213+ array (
214+ 'option_name ' => $ option_name ,
215+ 'option_value ' => 'b:0; ' ,
216+ 'autoload ' => 'yes ' ,
217+ )
218+ );
219+ // Clear alloptions cache so get_option() reads from DB.
220+ wp_cache_delete ( 'alloptions ' , 'options ' );
221+ wp_cache_delete ( $ option_name , 'options ' );
222+
223+ $ result = get_option ( $ option_name , 'should-not-be-returned ' );
224+
225+ // Cleanup.
226+ $ wpdb ->delete ( $ wpdb ->options , array ( 'option_name ' => $ option_name ) );
227+ wp_cache_delete ( 'alloptions ' , 'options ' );
228+ wp_cache_delete ( $ option_name , 'options ' );
229+
230+ $ this ->assertFalse ( $ result , 'get_option() should return false when the stored value is a serialized boolean false. ' );
231+ }
232+
164233 /**
165234 * @ticket 23289
166235 *
0 commit comments