Changeset 34745
- Timestamp:
- 10/01/2015 05:33:58 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/shortcodes.php
r34744 r34745 89 89 function add_shortcode($tag, $func) { 90 90 global $shortcode_tags; 91 92 if ( '' == trim( $tag ) ) { 93 $message = __( 'Invalid shortcode name. Empty name given.' ); 94 _doing_it_wrong( __FUNCTION__, $message, '4.4.0' ); 95 return; 96 } 97 98 if ( 0 !== preg_match( '@[<>&/\[\]\x00-\x20]@', $tag ) ) { 99 $message = sprintf( __( 'Invalid shortcode name: %s Do not use spaces or reserved chars: & / < > [ ]' ), $tag ); 100 _doing_it_wrong( __FUNCTION__, $message, '4.4.0' ); 101 return; 102 } 103 91 104 $shortcode_tags[ $tag ] = $func; 92 105 } -
trunk/tests/phpunit/tests/shortcode.php
r33740 r34745 540 540 remove_shortcode( 'foo' ); 541 541 } 542 543 /** 544 * Make sure invalid shortcode names are not allowed. 545 * 546 * @dataProvider data_registration_bad 547 * @expectedIncorrectUsage add_shortcode 548 */ 549 function test_registration_bad( $input, $expected ) { 550 return $this->sub_registration( $input, $expected ); 551 } 552 553 /** 554 * Make sure valid shortcode names are allowed. 555 * 556 * @dataProvider data_registration_good 557 */ 558 function test_registration_good( $input, $expected ) { 559 return $this->sub_registration( $input, $expected ); 560 } 561 562 function sub_registration( $input, $expected ) { 563 add_shortcode( $input, '' ); 564 $actual = shortcode_exists( $input ); 565 $test = $this->assertEquals( $expected, $actual ); 566 if ( $actual ) remove_shortcode( $input ); 567 return $test; 568 } 569 570 function data_registration_bad() { 571 return array( 572 array( 573 '<html>', 574 false, 575 ), 576 array( 577 '[shortcode]', 578 false, 579 ), 580 array( 581 'bad/', 582 false, 583 ), 584 array( 585 '/bad', 586 false, 587 ), 588 array( 589 'bad space', 590 false, 591 ), 592 array( 593 '&', 594 false, 595 ), 596 array( 597 '', 598 false, 599 ), 600 ); 601 } 602 603 function data_registration_good() { 604 return array( 605 array( 606 'good!', 607 true, 608 ), 609 array( 610 'plain', 611 true, 612 ), 613 array( 614 'unreserved!#$%()*+,-.;?@^_{|}~chars', 615 true, 616 ), 617 ); 618 } 542 619 }
Note: See TracChangeset
for help on using the changeset viewer.