Changeset 33381
- Timestamp:
- 07/23/2015 04:49:25 AM (10 years ago)
- Location:
- branches/4.0
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.0/src/wp-includes/class-wp-embed.php
r29707 r33381 61 61 62 62 // Do the shortcode (only the [embed] one is registered) 63 $content = do_shortcode( $content );63 $content = do_shortcode( $content, true ); 64 64 65 65 // Put the original shortcodes back … … 327 327 */ 328 328 public function autoembed( $content ) { 329 // Strip newlines from all elements. 330 $content = wp_replace_in_html_tags( $content, array( "\n" => " " ) ); 331 332 // Find URLs that are on their own line. 329 333 return preg_replace_callback( '|^\s*(https?://[^\s"]+)\s*$|im', array( $this, 'autoembed_callback' ), $content ); 330 334 } -
branches/4.0/src/wp-includes/formatting.php
r32189 r33381 406 406 $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines 407 407 408 // Strip newlines from all elements. 409 $pee = wp_replace_in_html_tags( $pee, array( "\n" => " " ) ); 410 408 411 if ( strpos( $pee, '<option' ) !== false ) { 409 412 // no P/BR around option … … 458 461 459 462 return $pee; 463 } 464 465 /** 466 * Replace characters or phrases within HTML elements only. 467 * 468 * @since 4.2.3 469 * 470 * @param string $haystack The text which has to be formatted. 471 * @param array $replace_pairs In the form array('from' => 'to', ...). 472 * @return string The formatted text. 473 */ 474 function wp_replace_in_html_tags( $haystack, $replace_pairs ) { 475 // Find all elements. 476 $comments = 477 '!' // Start of comment, after the <. 478 . '(?:' // Unroll the loop: Consume everything until --> is found. 479 . '-(?!->)' // Dash not followed by end of comment. 480 . '[^\-]*+' // Consume non-dashes. 481 . ')*+' // Loop possessively. 482 . '(?:-->)?'; // End of comment. If not found, match all input. 483 484 $regex = 485 '/(' // Capture the entire match. 486 . '<' // Find start of element. 487 . '(?(?=!--)' // Is this a comment? 488 . $comments // Find end of comment. 489 . '|' 490 . '[^>]*>?' // Find end of element. If not found, match all input. 491 . ')' 492 . ')/s'; 493 494 $textarr = preg_split( $regex, $haystack, -1, PREG_SPLIT_DELIM_CAPTURE ); 495 $changed = false; 496 497 // Optimize when searching for one item. 498 if ( 1 === count( $replace_pairs ) ) { 499 // Extract $needle and $replace. 500 foreach ( $replace_pairs as $needle => $replace ); 501 502 // Loop through delimeters (elements) only. 503 for ( $i = 1, $c = count( $textarr ); $i < $c; $i += 2 ) { 504 if ( false !== strpos( $textarr[$i], $needle ) ) { 505 $textarr[$i] = str_replace( $needle, $replace, $textarr[$i] ); 506 $changed = true; 507 } 508 } 509 } else { 510 // Extract all $needles. 511 $needles = array_keys( $replace_pairs ); 512 513 // Loop through delimeters (elements) only. 514 for ( $i = 1, $c = count( $textarr ); $i < $c; $i += 2 ) { 515 foreach ( $needles as $needle ) { 516 if ( false !== strpos( $textarr[$i], $needle ) ) { 517 $textarr[$i] = strtr( $textarr[$i], $replace_pairs ); 518 $changed = true; 519 // After one strtr() break out of the foreach loop and look at next element. 520 break; 521 } 522 } 523 } 524 } 525 526 if ( $changed ) { 527 $haystack = implode( $textarr ); 528 } 529 530 return $haystack; 460 531 } 461 532 -
branches/4.0/src/wp-includes/kses.php
r30426 r33381 495 495 496 496 /** 497 * Filters one attribute only and ensures its value is allowed. 498 * 499 * This function has the advantage of being more secure than esc_attr() and can 500 * escape data in some situations where wp_kses() must strip the whole attribute. 501 * 502 * @since 4.2.3 503 * 504 * @param string $string The 'whole' attribute, including name and value. 505 * @param string $element The element name to which the attribute belongs. 506 * @return string Filtered attribute. 507 */ 508 function wp_kses_one_attr( $string, $element ) { 509 $uris = array('xmlns', 'profile', 'href', 'src', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action'); 510 $allowed_html = wp_kses_allowed_html( 'post' ); 511 $allowed_protocols = wp_allowed_protocols(); 512 $string = wp_kses_no_null( $string, array( 'slash_zero' => 'keep' ) ); 513 $string = wp_kses_js_entities( $string ); 514 $string = wp_kses_normalize_entities( $string ); 515 516 // Preserve leading and trailing whitespace. 517 $matches = array(); 518 preg_match('/^\s*/', $string, $matches); 519 $lead = $matches[0]; 520 preg_match('/\s*$/', $string, $matches); 521 $trail = $matches[0]; 522 if ( empty( $trail ) ) { 523 $string = substr( $string, strlen( $lead ) ); 524 } else { 525 $string = substr( $string, strlen( $lead ), -strlen( $trail ) ); 526 } 527 528 // Parse attribute name and value from input. 529 $split = preg_split( '/\s*=\s*/', $string, 2 ); 530 $name = $split[0]; 531 if ( count( $split ) == 2 ) { 532 $value = $split[1]; 533 534 // Remove quotes surrounding $value. 535 // Also guarantee correct quoting in $string for this one attribute. 536 if ( '' == $value ) { 537 $quote = ''; 538 } else { 539 $quote = $value[0]; 540 } 541 if ( '"' == $quote || "'" == $quote ) { 542 if ( substr( $value, -1 ) != $quote ) { 543 return ''; 544 } 545 $value = substr( $value, 1, -1 ); 546 } else { 547 $quote = '"'; 548 } 549 550 // Sanitize quotes and angle braces. 551 $value = htmlspecialchars( $value, ENT_QUOTES, null, false ); 552 553 // Sanitize URI values. 554 if ( in_array( strtolower( $name ), $uris ) ) { 555 $value = wp_kses_bad_protocol( $value, $allowed_protocols ); 556 } 557 558 $string = "$name=$quote$value$quote"; 559 $vless = 'n'; 560 } else { 561 $value = ''; 562 $vless = 'y'; 563 } 564 565 // Sanitize attribute by name. 566 wp_kses_attr_check( $name, $value, $string, $vless, $element, $allowed_html ); 567 568 // Restore whitespace. 569 return $lead . $string . $trail; 570 } 571 572 /** 497 573 * Return a list of allowed tags and attributes for a given context. 498 574 * … … 715 791 # in $attr2 716 792 $attr2 = ''; 717 718 $allowed_attr = $allowed_html[strtolower($element)]; 719 foreach ($attrarr as $arreach) { 720 if ( ! isset( $allowed_attr[strtolower($arreach['name'])] ) ) 721 continue; # the attribute is not allowed 722 723 $current = $allowed_attr[strtolower($arreach['name'])]; 724 if ( $current == '' ) 725 continue; # the attribute is not allowed 726 727 if ( strtolower( $arreach['name'] ) == 'style' ) { 728 $orig_value = $arreach['value']; 729 $value = safecss_filter_attr( $orig_value ); 730 731 if ( empty( $value ) ) 732 continue; 733 734 $arreach['value'] = $value; 735 $arreach['whole'] = str_replace( $orig_value, $value, $arreach['whole'] ); 793 foreach ( $attrarr as $arreach ) { 794 if ( wp_kses_attr_check( $arreach['name'], $arreach['value'], $arreach['whole'], $arreach['vless'], $element, $allowed_html ) ) { 795 $attr2 .= ' '.$arreach['whole']; 736 796 } 737 738 if ( ! is_array($current) ) { 739 $attr2 .= ' '.$arreach['whole']; 740 # there are no checks 741 742 } else { 743 # there are some checks 744 $ok = true; 745 foreach ($current as $currkey => $currval) { 746 if ( ! wp_kses_check_attr_val($arreach['value'], $arreach['vless'], $currkey, $currval) ) { 747 $ok = false; 748 break; 749 } 750 } 751 752 if ( $ok ) 753 $attr2 .= ' '.$arreach['whole']; # it passed them 754 } # if !is_array($current) 755 } # foreach 797 } 756 798 757 799 # Remove any "<" or ">" characters … … 759 801 760 802 return "<$element$attr2$xhtml_slash>"; 803 } 804 805 /** 806 * Determine whether an attribute is allowed. 807 * 808 * @since 4.2.3 809 * 810 * @param string $name The attribute name. Returns empty string when not allowed. 811 * @param string $value The attribute value. Returns a filtered value. 812 * @param string $whole The name=value input. Returns filtered input. 813 * @param string $vless 'y' when attribute like "enabled", otherwise 'n'. 814 * @param string $element The name of the element to which this attribute belongs. 815 * @param array $allowed_html The full list of allowed elements and attributes. 816 * @return bool Is the attribute allowed? 817 */ 818 function wp_kses_attr_check( &$name, &$value, &$whole, $vless, $element, $allowed_html ) { 819 $allowed_attr = $allowed_html[strtolower( $element )]; 820 821 $name_low = strtolower( $name ); 822 if ( ! isset( $allowed_attr[$name_low] ) || '' == $allowed_attr[$name_low] ) { 823 $name = $value = $whole = ''; 824 return false; 825 } 826 827 if ( 'style' == $name_low ) { 828 $new_value = safecss_filter_attr( $value ); 829 830 if ( empty( $new_value ) ) { 831 $name = $value = $whole = ''; 832 return false; 833 } 834 835 $whole = str_replace( $value, $new_value, $whole ); 836 $value = $new_value; 837 } 838 839 if ( is_array( $allowed_attr[$name_low] ) ) { 840 // there are some checks 841 foreach ( $allowed_attr[$name_low] as $currkey => $currval ) { 842 if ( ! wp_kses_check_attr_val( $value, $vless, $currkey, $currval ) ) { 843 $name = $value = $whole = ''; 844 return false; 845 } 846 } 847 } 848 849 return true; 761 850 } 762 851 … … 888 977 889 978 return $attrarr; 979 } 980 981 /** 982 * Finds all attributes of an HTML element. 983 * 984 * Does not modify input. May return "evil" output. 985 * 986 * Based on wp_kses_split2() and wp_kses_attr() 987 * 988 * @since 4.2.3 989 * 990 * @param string $element HTML element/tag 991 * @return array|bool List of attributes found in $element. Returns false on failure. 992 */ 993 function wp_kses_attr_parse( $element ) { 994 $valid = preg_match('%^(<\s*)(/\s*)?([a-zA-Z0-9]+\s*)([^>]*)(>?)$%', $element, $matches); 995 if ( 1 !== $valid ) { 996 return false; 997 } 998 999 $begin = $matches[1]; 1000 $slash = $matches[2]; 1001 $elname = $matches[3]; 1002 $attr = $matches[4]; 1003 $end = $matches[5]; 1004 1005 if ( '' !== $slash ) { 1006 // Closing elements do not get parsed. 1007 return false; 1008 } 1009 1010 // Is there a closing XHTML slash at the end of the attributes? 1011 if ( 1 === preg_match( '%\s*/\s*$%', $attr, $matches ) ) { 1012 $xhtml_slash = $matches[0]; 1013 $attr = substr( $attr, 0, -strlen( $xhtml_slash ) ); 1014 } else { 1015 $xhtml_slash = ''; 1016 } 1017 1018 // Split it 1019 $attrarr = wp_kses_hair_parse( $attr ); 1020 if ( false === $attrarr ) { 1021 return false; 1022 } 1023 1024 // Make sure all input is returned by adding front and back matter. 1025 array_unshift( $attrarr, $begin . $slash . $elname ); 1026 array_push( $attrarr, $xhtml_slash . $end ); 1027 1028 return $attrarr; 1029 } 1030 1031 /** 1032 * Builds an attribute list from string containing attributes. 1033 * 1034 * Does not modify input. May return "evil" output. 1035 * In case of unexpected input, returns false instead of stripping things. 1036 * 1037 * Based on wp_kses_hair() but does not return a multi-dimensional array. 1038 * 1039 * @since 4.2.3 1040 * 1041 * @param string $attr Attribute list from HTML element to closing HTML element tag 1042 * @return array|bool List of attributes found in $attr. Returns false on failure. 1043 */ 1044 function wp_kses_hair_parse( $attr ) { 1045 if ( '' === $attr ) { 1046 return array(); 1047 } 1048 1049 $regex = 1050 '(?:' 1051 . '[-a-zA-Z:]+' // Attribute name. 1052 . '|' 1053 . '\[\[?[^\[\]]+\]\]?' // Shortcode in the name position implies unfiltered_html. 1054 . ')' 1055 . '(?:' // Attribute value. 1056 . '\s*=\s*' // All values begin with '=' 1057 . '(?:' 1058 . '"[^"]*"' // Double-quoted 1059 . '|' 1060 . "'[^']*'" // Single-quoted 1061 . '|' 1062 . '[^\s"\']+' // Non-quoted 1063 . '(?:\s|$)' // Must have a space 1064 . ')' 1065 . '|' 1066 . '(?:\s|$)' // If attribute has no value, space is required. 1067 . ')' 1068 . '\s*'; // Trailing space is optional except as mentioned above. 1069 1070 // Although it is possible to reduce this procedure to a single regexp, 1071 // we must run that regexp twice to get exactly the expected result. 1072 1073 $validation = "%^($regex)+$%"; 1074 $extraction = "%$regex%"; 1075 1076 if ( 1 === preg_match( $validation, $attr ) ) { 1077 preg_match_all( $extraction, $attr, $attrarr ); 1078 return $attrarr[0]; 1079 } else { 1080 return false; 1081 } 890 1082 } 891 1083 -
branches/4.0/src/wp-includes/shortcodes.php
r29207 r33381 189 189 * 190 190 * @param string $content Content to search for shortcodes 191 * @param bool $ignore_html When true, shortcodes inside HTML elements will be skipped. 191 192 * @return string Content with shortcodes filtered out. 192 193 */ 193 function do_shortcode( $content) {194 function do_shortcode( $content, $ignore_html = false ) { 194 195 global $shortcode_tags; 195 196 … … 201 202 return $content; 202 203 204 $tagnames = array_keys($shortcode_tags); 205 $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); 206 $pattern = "/\\[($tagregexp)/s"; 207 208 if ( 1 !== preg_match( $pattern, $content ) ) { 209 // Avoids parsing HTML when there are no shortcodes or embeds anyway. 210 return $content; 211 } 212 213 $content = do_shortcodes_in_html_tags( $content, $ignore_html ); 214 203 215 $pattern = get_shortcode_regex(); 204 return preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content ); 216 $content = preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content ); 217 218 // Always restore square braces so we don't break things like <!--[if IE ]> 219 $content = unescape_invalid_shortcodes( $content ); 220 221 return $content; 205 222 } 206 223 … … 296 313 297 314 /** 315 * Search only inside HTML elements for shortcodes and process them. 316 * 317 * Any [ or ] characters remaining inside elements will be HTML encoded 318 * to prevent interference with shortcodes that are outside the elements. 319 * Assumes $content processed by KSES already. Users with unfiltered_html 320 * capability may get unexpected output if angle braces are nested in tags. 321 * 322 * @since 4.2.3 323 * 324 * @param string $content Content to search for shortcodes 325 * @param bool $ignore_html When true, all square braces inside elements will be encoded. 326 * @return string Content with shortcodes filtered out. 327 */ 328 function do_shortcodes_in_html_tags( $content, $ignore_html ) { 329 // Normalize entities in unfiltered HTML before adding placeholders. 330 $trans = array( '[' => '[', ']' => ']' ); 331 $content = strtr( $content, $trans ); 332 $trans = array( '[' => '[', ']' => ']' ); 333 334 $pattern = get_shortcode_regex(); 335 336 $comment_regex = 337 '!' // Start of comment, after the <. 338 . '(?:' // Unroll the loop: Consume everything until --> is found. 339 . '-(?!->)' // Dash not followed by end of comment. 340 . '[^\-]*+' // Consume non-dashes. 341 . ')*+' // Loop possessively. 342 . '(?:-->)?'; // End of comment. If not found, match all input. 343 344 $regex = 345 '/(' // Capture the entire match. 346 . '<' // Find start of element. 347 . '(?(?=!--)' // Is this a comment? 348 . $comment_regex // Find end of comment. 349 . '|' 350 . '[^>]*>?' // Find end of element. If not found, match all input. 351 . ')' 352 . ')/s'; 353 354 $textarr = preg_split( $regex, $content, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ); 355 356 foreach ( $textarr as &$element ) { 357 if ( '<' !== $element[0] ) { 358 continue; 359 } 360 361 $noopen = false === strpos( $element, '[' ); 362 $noclose = false === strpos( $element, ']' ); 363 if ( $noopen || $noclose ) { 364 // This element does not contain shortcodes. 365 if ( $noopen xor $noclose ) { 366 // Need to encode stray [ or ] chars. 367 $element = strtr( $element, $trans ); 368 } 369 continue; 370 } 371 372 if ( $ignore_html || '<!--' === substr( $element, 0, 4 ) ) { 373 // Encode all [ and ] chars. 374 $element = strtr( $element, $trans ); 375 continue; 376 } 377 378 $attributes = wp_kses_attr_parse( $element ); 379 if ( false === $attributes ) { 380 // Looks like we found some crazy unfiltered HTML. Skipping it for sanity. 381 $element = strtr( $element, $trans ); 382 continue; 383 } 384 385 // Get element name 386 $front = array_shift( $attributes ); 387 $back = array_pop( $attributes ); 388 $matches = array(); 389 preg_match('%[a-zA-Z0-9]+%', $front, $matches); 390 $elname = $matches[0]; 391 392 // Look for shortcodes in each attribute separately. 393 foreach ( $attributes as &$attr ) { 394 $open = strpos( $attr, '[' ); 395 $close = strpos( $attr, ']' ); 396 if ( false === $open || false === $close ) { 397 continue; // Go to next attribute. Square braces will be escaped at end of loop. 398 } 399 $double = strpos( $attr, '"' ); 400 $single = strpos( $attr, "'" ); 401 if ( ( false === $single || $open < $single ) && ( false === $double || $open < $double ) ) { 402 // $attr like '[shortcode]' or 'name = [shortcode]' implies unfiltered_html. 403 // In this specific situation we assume KSES did not run because the input 404 // was written by an administrator, so we should avoid changing the output 405 // and we do not need to run KSES here. 406 $attr = preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $attr ); 407 } else { 408 // $attr like 'name = "[shortcode]"' or "name = '[shortcode]'" 409 // We do not know if $content was unfiltered. Assume KSES ran before shortcodes. 410 $count = 0; 411 $new_attr = preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $attr, -1, $count ); 412 if ( $count > 0 ) { 413 // Sanitize the shortcode output using KSES. 414 $new_attr = wp_kses_one_attr( $new_attr, $elname ); 415 if ( '' !== $new_attr ) { 416 // The shortcode is safe to use now. 417 $attr = $new_attr; 418 } 419 } 420 } 421 } 422 $element = $front . implode( '', $attributes ) . $back; 423 424 // Now encode any remaining [ or ] chars. 425 $element = strtr( $element, $trans ); 426 } 427 428 $content = implode( '', $textarr ); 429 430 return $content; 431 } 432 433 /** 434 * Remove placeholders added by do_shortcodes_in_html_tags(). 435 * 436 * @since 4.2.3 437 * 438 * @param string $content Content to search for placeholders. 439 * @return string Content with placeholders removed. 440 */ 441 function unescape_invalid_shortcodes( $content ) { 442 // Clean up entire string, avoids re-parsing HTML. 443 $trans = array( '[' => '[', ']' => ']' ); 444 $content = strtr( $content, $trans ); 445 446 return $content; 447 } 448 449 /** 298 450 * Retrieve all attributes from the shortcodes tag. 299 451 * … … 394 546 return $content; 395 547 548 $content = do_shortcodes_in_html_tags( $content, true ); 549 396 550 $pattern = get_shortcode_regex(); 397 398 return preg_replace_callback( "/$pattern/s", 'strip_shortcode_tag', $content ); 551 $content = preg_replace_callback( "/$pattern/s", 'strip_shortcode_tag', $content ); 552 553 // Always restore square braces so we don't break things like <!--[if IE ]> 554 $content = unescape_invalid_shortcodes( $content ); 555 556 return $content; 399 557 } 400 558 -
branches/4.0/tests/phpunit/tests/kses.php
r28942 r33381 412 412 ); 413 413 } 414 415 /** 416 * Test new function wp_kses_hair_parse(). 417 * 418 * @dataProvider data_hair_parse 419 */ 420 function test_hair_parse( $input, $output ) { 421 return $this->assertEquals( $output, wp_kses_hair_parse( $input ) ); 422 } 423 424 function data_hair_parse() { 425 return array( 426 array( 427 'title="hello" href="#" id="my_id" ', 428 array( 'title="hello" ', 'href="#" ', 'id="my_id" ' ), 429 ), 430 array( 431 '[shortcode attr="value"] href="http://www.google.com/"title="moo"disabled', 432 array( '[shortcode attr="value"] ', 'href="http://www.google.com/"', 'title="moo"', 'disabled' ), 433 ), 434 array( 435 '', 436 array(), 437 ), 438 array( 439 'a', 440 array( 'a' ), 441 ), 442 array( 443 'title="hello"disabled href=# id=\'my_id\'', 444 array( 'title="hello"', 'disabled ', 'href=# ', "id='my_id'" ), 445 ), 446 array( 447 ' ', // Calling function is expected to strip leading whitespace. 448 false, 449 ), 450 array( 451 'abcd=abcd"abcd"', 452 false, 453 ), 454 array( 455 "array[1]='z'z'z'z", 456 false, 457 ), 458 ); 459 } 460 461 /** 462 * Test new function wp_kses_attr_parse(). 463 * 464 * @dataProvider data_attr_parse 465 */ 466 function test_attr_parse( $input, $output ) { 467 return $this->assertEquals( $output, wp_kses_attr_parse( $input ) ); 468 } 469 470 function data_attr_parse() { 471 return array( 472 array( 473 '<a title="hello" href="#" id="my_id" >', 474 array( '<a ', 'title="hello" ', 'href="#" ', 'id="my_id" ', '>' ), 475 ), 476 array( 477 '<a [shortcode attr="value"] href="http://www.google.com/"title="moo"disabled>', 478 array( '<a ', '[shortcode attr="value"] ', 'href="http://www.google.com/"', 'title="moo"', 'disabled', '>' ), 479 ), 480 array( 481 '', 482 false, 483 ), 484 array( 485 'a', 486 false, 487 ), 488 array( 489 '<a>', 490 array( '<a', '>' ), 491 ), 492 array( 493 '<a%%&&**>', 494 false, 495 ), 496 array( 497 '<a title="hello"disabled href=# id=\'my_id\'>', 498 array( '<a ', 'title="hello"', 'disabled ', 'href=# ', "id='my_id'", ">" ), 499 ), 500 array( 501 '<a >', 502 array( '<a ', '>' ), 503 ), 504 array( 505 '<a abcd=abcd"abcd">', 506 false, 507 ), 508 array( 509 "<a array[1]='z'z'z'z>", 510 false, 511 ), 512 array( 513 '<img title="hello" src="#" id="my_id" />', 514 array( '<img ', 'title="hello" ', 'src="#" ', 'id="my_id"', ' />' ), 515 ), 516 ); 517 } 518 519 /** 520 * Test new function wp_kses_one_attr(). 521 * 522 * @dataProvider data_one_attr 523 */ 524 function test_one_attr( $element, $input, $output ) { 525 return $this->assertEquals( $output, wp_kses_one_attr( $input, $element ) ); 526 } 527 528 function data_one_attr() { 529 return array( 530 array( 531 'a', 532 ' title="hello" ', 533 ' title="hello" ', 534 ), 535 array( 536 'a', 537 'title = "hello"', 538 'title="hello"', 539 ), 540 array( 541 'a', 542 "title='hello'", 543 "title='hello'", 544 ), 545 array( 546 'a', 547 'title=hello', 548 'title="hello"', 549 ), 550 array( 551 'a', 552 'href="javascript:alert(1)"', 553 'href="alert(1)"', 554 ), 555 array( 556 'a', 557 'style ="style "', 558 'style="style"', 559 ), 560 array( 561 'a', 562 'style="style "', 563 'style="style"', 564 ), 565 array( 566 'a', 567 'style ="style ="', 568 '', 569 ), 570 array( 571 'img', 572 'src="mypic.jpg"', 573 'src="mypic.jpg"', 574 ), 575 array( 576 'img', 577 'onerror=alert(1)', 578 '', 579 ), 580 array( 581 'img', 582 'title=>', 583 'title=">"', 584 ), 585 array( 586 'img', 587 'title="&garbage";"', 588 'title="&garbage";"', 589 ), 590 ); 591 } 414 592 } -
branches/4.0/tests/phpunit/tests/shortcode.php
r32148 r33381 397 397 398 398 /** 399 * Check for bugginess using normal input with latest patches. 400 * 401 * @dataProvider data_escaping 402 */ 403 function test_escaping( $input, $output ) { 404 return $this->assertEquals( $output, do_shortcode( $input ) ); 405 } 406 407 function data_escaping() { 408 return array( 409 array( 410 '<!--[if lt IE 7]>', 411 '<!--[if lt IE 7]>', 412 ), 413 array( 414 '[gallery title="<div>hello</div>"]', 415 '', 416 ), 417 array( 418 '[caption caption="test" width="2"]<div>hello</div>[/caption]', 419 '<div style="width: 12px" class="wp-caption alignnone"><div>hello</div><p class="wp-caption-text">test</p></div>', 420 ), 421 array( 422 '<div [gallery]>', 423 '<div >', 424 ), 425 array( 426 '<div [[gallery]]>', 427 '<div [gallery]>', 428 ), 429 array( 430 '[gallery]<div>Hello</div>[/gallery]', 431 '', 432 ), 433 ); 434 } 435 436 /** 437 * Check for bugginess using normal input with latest patches. 438 * 439 * @dataProvider data_escaping2 440 */ 441 function test_escaping2( $input, $output ) { 442 return $this->assertEquals( $output, strip_shortcodes( $input ) ); 443 } 444 445 function data_escaping2() { 446 return array( 447 array( 448 '<!--[if lt IE 7]>', 449 '<!--[if lt IE 7]>', 450 ), 451 array( 452 '[gallery title="<div>hello</div>"]', 453 '', 454 ), 455 array( 456 '[caption caption="test" width="2"]<div>hello</div>[/caption]', 457 '', 458 ), 459 array( 460 '<div [gallery]>', // Shortcodes will never be stripped inside elements. 461 '<div [gallery]>', 462 ), 463 array( 464 '<div [[gallery]]>', // Shortcodes will never be stripped inside elements. 465 '<div [[gallery]]>', 466 ), 467 array( 468 '[gallery]<div>Hello</div>[/gallery]', 469 '', 470 ), 471 ); 472 } 473 474 /** 399 475 * @ticket 26343 400 476 */
Note: See TracChangeset
for help on using the changeset viewer.