Changeset 29797
- Timestamp:
- 09/30/2014 02:03:49 PM (10 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/date.php
r29479 r29797 314 314 case 'IN': 315 315 case 'NOT IN': 316 return '(' . implode( ',', array_map( 'intval', (array) $value ) ) . ')'; 316 $value = (array) $value; 317 318 // Remove non-numeric values. 319 $value = array_filter( $value, 'is_numeric' ); 320 321 if ( empty( $value ) ) { 322 return false; 323 } 324 325 return '(' . implode( ',', array_map( 'intval', $value ) ) . ')'; 317 326 318 327 case 'BETWEEN': 319 328 case 'NOT BETWEEN': 320 if ( ! is_array( $value ) || 2 != count( $value ) || ! isset( $value[0] ) || ! isset( $value[1] ) )329 if ( ! is_array( $value ) || 2 != count( $value ) ) { 321 330 $value = array( $value, $value ); 331 } else { 332 $value = array_values( $value ); 333 } 334 335 // If either value is non-numeric, bail. 336 foreach ( $value as $v ) { 337 if ( ! is_numeric( $v ) ) { 338 return false; 339 } 340 } 322 341 323 342 $value = array_map( 'intval', $value ); … … 326 345 327 346 default; 347 if ( ! is_numeric( $value ) ) { 348 return false; 349 } 350 328 351 return (int) $value; 329 352 } -
trunk/tests/phpunit/tests/date/query.php
r29794 r29797 230 230 } 231 231 232 /** 233 * @ticket 29801 234 */ 232 235 public function test_build_value_compare_in() { 233 236 $q = new WP_Date_Query( array() ); … … 239 242 // Single non-integer 240 243 $found = $q->build_value( 'IN', 'foo' ); 241 $this->assert Same( '(0)',$found );244 $this->assertFalse( $found ); 242 245 243 246 // Array of integers … … 247 250 // Array containing non-integers 248 251 $found = $q->build_value( 'IN', array( 1, 'foo', 7 ) ); 249 $this->assertSame( '(1,0,7)', $found ); 250 } 251 252 $this->assertSame( '(1,7)', $found ); 253 } 254 255 /** 256 * @ticket 29801 257 */ 252 258 public function test_build_value_compare_not_in() { 253 259 $q = new WP_Date_Query( array() ); … … 259 265 // Single non-integer 260 266 $found = $q->build_value( 'NOT IN', 'foo' ); 261 $this->assert Same( '(0)',$found );267 $this->assertFalse( $found ); 262 268 263 269 // Array of integers … … 267 273 // Array containing non-integers 268 274 $found = $q->build_value( 'NOT IN', array( 1, 'foo', 7 ) ); 269 $this->assertSame( '(1, 0,7)', $found );275 $this->assertSame( '(1,7)', $found ); 270 276 } 271 277 … … 278 284 279 285 /** 280 * @t odo This is a bug. Should return false when non-numeric286 * @ticket 29801 281 287 */ 282 288 public function test_build_value_compare_between_single_non_numeric() { … … 284 290 285 291 $found = $q->build_value( 'BETWEEN', 'foo' ); 286 $this->assert Same( '0 AND 0',$found );287 } 288 289 /** 290 * @t odo This is a bug292 $this->assertFalse( $found ); 293 } 294 295 /** 296 * @ticket 29801 291 297 */ 292 298 public function test_build_value_compare_between_array_with_other_than_two_items() { … … 294 300 295 301 $found = $q->build_value( 'BETWEEN', array( 2, 3, 4 ) ); 296 297 // array_map( 'intval', array( 298 // array( 2, 3, 4 ), 299 // array( 2, 3, 4 ), 300 // ) ); 301 $this->assertSame( '1 AND 1', $found ); 302 } 303 304 /** 305 * @todo This is a bug 302 $this->assertFalse( $found ); 303 } 304 305 /** 306 * @ticket 29801 306 307 */ 307 308 public function test_build_value_compare_between_incorrect_array_key() { … … 313 314 ) ); 314 315 315 // array_map( 'intval', array( 316 // array( 2 => 4, 3 => 5 ), 317 // array( 2 => 4, 3 => 5 ), 318 // ) ); 319 $this->assertSame( '1 AND 1', $found ); 320 } 321 316 $this->assertSame( '4 AND 5', $found ); 317 } 318 319 /** 320 * @ticket 29801 321 */ 322 322 public function test_build_value_compare_between_array_contains_non_numeric() { 323 323 $q = new WP_Date_Query( array() ); 324 324 325 325 $found = $q->build_value( 'BETWEEN', array( 2, 'foo' ) ); 326 $this->assert Same( '2 AND 0',$found );326 $this->assertFalse( $found ); 327 327 } 328 328 … … 341 341 } 342 342 343 /** 344 * @ticket 29801 345 */ 343 346 public function test_build_value_compare_not_between_single_non_numeric() { 344 347 $q = new WP_Date_Query( array() ); 345 348 346 349 $found = $q->build_value( 'NOT BETWEEN', 'foo' ); 347 $this->assert Same( '0 AND 0',$found );348 } 349 350 /** 351 * @t odo This is a bug350 $this->assertFalse( $found ); 351 } 352 353 /** 354 * @ticket 29801 352 355 */ 353 356 public function test_build_value_compare_not_between_array_with_other_than_two_items() { … … 355 358 356 359 $found = $q->build_value( 'NOT BETWEEN', array( 2, 3, 4 ) ); 357 358 // array_map( 'intval', array( 359 // array( 2, 3, 4 ), 360 // array( 2, 3, 4 ), 361 // ) ); 362 $this->assertSame( '1 AND 1', $found ); 363 } 364 365 /** 366 * @todo This is a bug 360 $this->assertFalse( $found ); 361 } 362 363 /** 364 * @ticket 29801 367 365 */ 368 366 public function test_build_value_compare_not_between_incorrect_array_key() { … … 374 372 ) ); 375 373 376 // array_map( 'intval', array( 377 // array( 2 => 4, 3 => 5 ), 378 // array( 2 => 4, 3 => 5 ), 379 // ) ); 380 $this->assertSame( '1 AND 1', $found ); 381 } 382 374 $this->assertSame( '4 AND 5', $found ); 375 } 376 377 /** 378 * @ticket 29801 379 */ 383 380 public function test_build_value_compare_not_between_array_contains_non_numeric() { 384 381 $q = new WP_Date_Query( array() ); 385 382 386 383 $found = $q->build_value( 'NOT BETWEEN', array( 2, 'foo' ) ); 387 $this->assert Same( '2 AND 0',$found );384 $this->assertFalse( $found ); 388 385 } 389 386 … … 403 400 404 401 /** 405 * @t odo This is probably a bug - ought to return false402 * @ticket 29801 406 403 */ 407 404 public function test_build_value_compare_default_value_non_numeric() { … … 409 406 410 407 $found = $q->build_value( 'foo', 'foo' ); 411 $this->assert Same( 0,$found );408 $this->assertFalse( $found ); 412 409 } 413 410
Note: See TracChangeset
for help on using the changeset viewer.