Changeset 33380
- Timestamp:
- 07/23/2015 04:36:55 AM (9 years ago)
- Location:
- branches/4.1
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/4.1/src/wp-includes/class-wp-embed.php
r30681 r33380 58 58 59 59 // Do the shortcode (only the [embed] one is registered) 60 $content = do_shortcode( $content );60 $content = do_shortcode( $content, true ); 61 61 62 62 // Put the original shortcodes back … … 313 313 */ 314 314 public function autoembed( $content ) { 315 // Strip newlines from all elements. 316 $content = wp_replace_in_html_tags( $content, array( "\n" => " " ) ); 317 318 // Find URLs that are on their own line. 315 319 return preg_replace_callback( '|^\s*(https?://[^\s"]+)\s*$|im', array( $this, 'autoembed_callback' ), $content ); 316 320 } -
branches/4.1/src/wp-includes/formatting.php
r32165 r33380 411 411 $pee = str_replace(array("\r\n", "\r"), "\n", $pee); // cross-platform newlines 412 412 413 // Strip newlines from all elements. 414 $pee = wp_replace_in_html_tags( $pee, array( "\n" => " " ) ); 415 413 416 if ( strpos( $pee, '<option' ) !== false ) { 414 417 // no P/BR around option … … 463 466 464 467 return $pee; 468 } 469 470 /** 471 * Replace characters or phrases within HTML elements only. 472 * 473 * @since 4.2.3 474 * 475 * @param string $haystack The text which has to be formatted. 476 * @param array $replace_pairs In the form array('from' => 'to', ...). 477 * @return string The formatted text. 478 */ 479 function wp_replace_in_html_tags( $haystack, $replace_pairs ) { 480 // Find all elements. 481 $comments = 482 '!' // Start of comment, after the <. 483 . '(?:' // Unroll the loop: Consume everything until --> is found. 484 . '-(?!->)' // Dash not followed by end of comment. 485 . '[^\-]*+' // Consume non-dashes. 486 . ')*+' // Loop possessively. 487 . '(?:-->)?'; // End of comment. If not found, match all input. 488 489 $regex = 490 '/(' // Capture the entire match. 491 . '<' // Find start of element. 492 . '(?(?=!--)' // Is this a comment? 493 . $comments // Find end of comment. 494 . '|' 495 . '[^>]*>?' // Find end of element. If not found, match all input. 496 . ')' 497 . ')/s'; 498 499 $textarr = preg_split( $regex, $haystack, -1, PREG_SPLIT_DELIM_CAPTURE ); 500 $changed = false; 501 502 // Optimize when searching for one item. 503 if ( 1 === count( $replace_pairs ) ) { 504 // Extract $needle and $replace. 505 foreach ( $replace_pairs as $needle => $replace ); 506 507 // Loop through delimeters (elements) only. 508 for ( $i = 1, $c = count( $textarr ); $i < $c; $i += 2 ) { 509 if ( false !== strpos( $textarr[$i], $needle ) ) { 510 $textarr[$i] = str_replace( $needle, $replace, $textarr[$i] ); 511 $changed = true; 512 } 513 } 514 } else { 515 // Extract all $needles. 516 $needles = array_keys( $replace_pairs ); 517 518 // Loop through delimeters (elements) only. 519 for ( $i = 1, $c = count( $textarr ); $i < $c; $i += 2 ) { 520 foreach ( $needles as $needle ) { 521 if ( false !== strpos( $textarr[$i], $needle ) ) { 522 $textarr[$i] = strtr( $textarr[$i], $replace_pairs ); 523 $changed = true; 524 // After one strtr() break out of the foreach loop and look at next element. 525 break; 526 } 527 } 528 } 529 } 530 531 if ( $changed ) { 532 $haystack = implode( $textarr ); 533 } 534 535 return $haystack; 465 536 } 466 537 -
branches/4.1/src/wp-includes/kses.php
r30726 r33380 529 529 530 530 /** 531 * Filters one attribute only and ensures its value is allowed. 532 * 533 * This function has the advantage of being more secure than esc_attr() and can 534 * escape data in some situations where wp_kses() must strip the whole attribute. 535 * 536 * @since 4.2.3 537 * 538 * @param string $string The 'whole' attribute, including name and value. 539 * @param string $element The element name to which the attribute belongs. 540 * @return string Filtered attribute. 541 */ 542 function wp_kses_one_attr( $string, $element ) { 543 $uris = array('xmlns', 'profile', 'href', 'src', 'cite', 'classid', 'codebase', 'data', 'usemap', 'longdesc', 'action'); 544 $allowed_html = wp_kses_allowed_html( 'post' ); 545 $allowed_protocols = wp_allowed_protocols(); 546 $string = wp_kses_no_null( $string, array( 'slash_zero' => 'keep' ) ); 547 $string = wp_kses_js_entities( $string ); 548 $string = wp_kses_normalize_entities( $string ); 549 550 // Preserve leading and trailing whitespace. 551 $matches = array(); 552 preg_match('/^\s*/', $string, $matches); 553 $lead = $matches[0]; 554 preg_match('/\s*$/', $string, $matches); 555 $trail = $matches[0]; 556 if ( empty( $trail ) ) { 557 $string = substr( $string, strlen( $lead ) ); 558 } else { 559 $string = substr( $string, strlen( $lead ), -strlen( $trail ) ); 560 } 561 562 // Parse attribute name and value from input. 563 $split = preg_split( '/\s*=\s*/', $string, 2 ); 564 $name = $split[0]; 565 if ( count( $split ) == 2 ) { 566 $value = $split[1]; 567 568 // Remove quotes surrounding $value. 569 // Also guarantee correct quoting in $string for this one attribute. 570 if ( '' == $value ) { 571 $quote = ''; 572 } else { 573 $quote = $value[0]; 574 } 575 if ( '"' == $quote || "'" == $quote ) { 576 if ( substr( $value, -1 ) != $quote ) { 577 return ''; 578 } 579 $value = substr( $value, 1, -1 ); 580 } else { 581 $quote = '"'; 582 } 583 584 // Sanitize quotes and angle braces. 585 $value = htmlspecialchars( $value, ENT_QUOTES, null, false ); 586 587 // Sanitize URI values. 588 if ( in_array( strtolower( $name ), $uris ) ) { 589 $value = wp_kses_bad_protocol( $value, $allowed_protocols ); 590 } 591 592 $string = "$name=$quote$value$quote"; 593 $vless = 'n'; 594 } else { 595 $value = ''; 596 $vless = 'y'; 597 } 598 599 // Sanitize attribute by name. 600 wp_kses_attr_check( $name, $value, $string, $vless, $element, $allowed_html ); 601 602 // Restore whitespace. 603 return $lead . $string . $trail; 604 } 605 606 /** 531 607 * Return a list of allowed tags and attributes for a given context. 532 608 * … … 748 824 # in $attr2 749 825 $attr2 = ''; 750 751 $allowed_attr = $allowed_html[strtolower($element)]; 752 foreach ($attrarr as $arreach) { 753 if ( ! isset( $allowed_attr[strtolower($arreach['name'])] ) ) 754 continue; # the attribute is not allowed 755 756 $current = $allowed_attr[strtolower($arreach['name'])]; 757 if ( $current == '' ) 758 continue; # the attribute is not allowed 759 760 if ( strtolower( $arreach['name'] ) == 'style' ) { 761 $orig_value = $arreach['value']; 762 $value = safecss_filter_attr( $orig_value ); 763 764 if ( empty( $value ) ) 765 continue; 766 767 $arreach['value'] = $value; 768 $arreach['whole'] = str_replace( $orig_value, $value, $arreach['whole'] ); 826 foreach ( $attrarr as $arreach ) { 827 if ( wp_kses_attr_check( $arreach['name'], $arreach['value'], $arreach['whole'], $arreach['vless'], $element, $allowed_html ) ) { 828 $attr2 .= ' '.$arreach['whole']; 769 829 } 770 771 if ( ! is_array($current) ) { 772 $attr2 .= ' '.$arreach['whole']; 773 # there are no checks 774 775 } else { 776 # there are some checks 777 $ok = true; 778 foreach ($current as $currkey => $currval) { 779 if ( ! wp_kses_check_attr_val($arreach['value'], $arreach['vless'], $currkey, $currval) ) { 780 $ok = false; 781 break; 782 } 783 } 784 785 if ( $ok ) 786 $attr2 .= ' '.$arreach['whole']; # it passed them 787 } # if !is_array($current) 788 } # foreach 830 } 789 831 790 832 # Remove any "<" or ">" characters … … 792 834 793 835 return "<$element$attr2$xhtml_slash>"; 836 } 837 838 /** 839 * Determine whether an attribute is allowed. 840 * 841 * @since 4.2.3 842 * 843 * @param string $name The attribute name. Returns empty string when not allowed. 844 * @param string $value The attribute value. Returns a filtered value. 845 * @param string $whole The name=value input. Returns filtered input. 846 * @param string $vless 'y' when attribute like "enabled", otherwise 'n'. 847 * @param string $element The name of the element to which this attribute belongs. 848 * @param array $allowed_html The full list of allowed elements and attributes. 849 * @return bool Is the attribute allowed? 850 */ 851 function wp_kses_attr_check( &$name, &$value, &$whole, $vless, $element, $allowed_html ) { 852 $allowed_attr = $allowed_html[strtolower( $element )]; 853 854 $name_low = strtolower( $name ); 855 if ( ! isset( $allowed_attr[$name_low] ) || '' == $allowed_attr[$name_low] ) { 856 $name = $value = $whole = ''; 857 return false; 858 } 859 860 if ( 'style' == $name_low ) { 861 $new_value = safecss_filter_attr( $value ); 862 863 if ( empty( $new_value ) ) { 864 $name = $value = $whole = ''; 865 return false; 866 } 867 868 $whole = str_replace( $value, $new_value, $whole ); 869 $value = $new_value; 870 } 871 872 if ( is_array( $allowed_attr[$name_low] ) ) { 873 // there are some checks 874 foreach ( $allowed_attr[$name_low] as $currkey => $currval ) { 875 if ( ! wp_kses_check_attr_val( $value, $vless, $currkey, $currval ) ) { 876 $name = $value = $whole = ''; 877 return false; 878 } 879 } 880 } 881 882 return true; 794 883 } 795 884 … … 921 1010 922 1011 return $attrarr; 1012 } 1013 1014 /** 1015 * Finds all attributes of an HTML element. 1016 * 1017 * Does not modify input. May return "evil" output. 1018 * 1019 * Based on wp_kses_split2() and wp_kses_attr() 1020 * 1021 * @since 4.2.3 1022 * 1023 * @param string $element HTML element/tag 1024 * @return array|bool List of attributes found in $element. Returns false on failure. 1025 */ 1026 function wp_kses_attr_parse( $element ) { 1027 $valid = preg_match('%^(<\s*)(/\s*)?([a-zA-Z0-9]+\s*)([^>]*)(>?)$%', $element, $matches); 1028 if ( 1 !== $valid ) { 1029 return false; 1030 } 1031 1032 $begin = $matches[1]; 1033 $slash = $matches[2]; 1034 $elname = $matches[3]; 1035 $attr = $matches[4]; 1036 $end = $matches[5]; 1037 1038 if ( '' !== $slash ) { 1039 // Closing elements do not get parsed. 1040 return false; 1041 } 1042 1043 // Is there a closing XHTML slash at the end of the attributes? 1044 if ( 1 === preg_match( '%\s*/\s*$%', $attr, $matches ) ) { 1045 $xhtml_slash = $matches[0]; 1046 $attr = substr( $attr, 0, -strlen( $xhtml_slash ) ); 1047 } else { 1048 $xhtml_slash = ''; 1049 } 1050 1051 // Split it 1052 $attrarr = wp_kses_hair_parse( $attr ); 1053 if ( false === $attrarr ) { 1054 return false; 1055 } 1056 1057 // Make sure all input is returned by adding front and back matter. 1058 array_unshift( $attrarr, $begin . $slash . $elname ); 1059 array_push( $attrarr, $xhtml_slash . $end ); 1060 1061 return $attrarr; 1062 } 1063 1064 /** 1065 * Builds an attribute list from string containing attributes. 1066 * 1067 * Does not modify input. May return "evil" output. 1068 * In case of unexpected input, returns false instead of stripping things. 1069 * 1070 * Based on wp_kses_hair() but does not return a multi-dimensional array. 1071 * 1072 * @since 4.2.3 1073 * 1074 * @param string $attr Attribute list from HTML element to closing HTML element tag 1075 * @return array|bool List of attributes found in $attr. Returns false on failure. 1076 */ 1077 function wp_kses_hair_parse( $attr ) { 1078 if ( '' === $attr ) { 1079 return array(); 1080 } 1081 1082 $regex = 1083 '(?:' 1084 . '[-a-zA-Z:]+' // Attribute name. 1085 . '|' 1086 . '\[\[?[^\[\]]+\]\]?' // Shortcode in the name position implies unfiltered_html. 1087 . ')' 1088 . '(?:' // Attribute value. 1089 . '\s*=\s*' // All values begin with '=' 1090 . '(?:' 1091 . '"[^"]*"' // Double-quoted 1092 . '|' 1093 . "'[^']*'" // Single-quoted 1094 . '|' 1095 . '[^\s"\']+' // Non-quoted 1096 . '(?:\s|$)' // Must have a space 1097 . ')' 1098 . '|' 1099 . '(?:\s|$)' // If attribute has no value, space is required. 1100 . ')' 1101 . '\s*'; // Trailing space is optional except as mentioned above. 1102 1103 // Although it is possible to reduce this procedure to a single regexp, 1104 // we must run that regexp twice to get exactly the expected result. 1105 1106 $validation = "%^($regex)+$%"; 1107 $extraction = "%$regex%"; 1108 1109 if ( 1 === preg_match( $validation, $attr ) ) { 1110 preg_match_all( $extraction, $attr, $attrarr ); 1111 return $attrarr[0]; 1112 } else { 1113 return false; 1114 } 923 1115 } 924 1116 -
branches/4.1/src/wp-includes/shortcodes.php
r30545 r33380 182 182 * 183 183 * @param string $content Content to search for shortcodes 184 * @param bool $ignore_html When true, shortcodes inside HTML elements will be skipped. 184 185 * @return string Content with shortcodes filtered out. 185 186 */ 186 function do_shortcode( $content) {187 function do_shortcode( $content, $ignore_html = false ) { 187 188 global $shortcode_tags; 188 189 … … 194 195 return $content; 195 196 197 $tagnames = array_keys($shortcode_tags); 198 $tagregexp = join( '|', array_map('preg_quote', $tagnames) ); 199 $pattern = "/\\[($tagregexp)/s"; 200 201 if ( 1 !== preg_match( $pattern, $content ) ) { 202 // Avoids parsing HTML when there are no shortcodes or embeds anyway. 203 return $content; 204 } 205 206 $content = do_shortcodes_in_html_tags( $content, $ignore_html ); 207 196 208 $pattern = get_shortcode_regex(); 197 return preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content ); 209 $content = preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $content ); 210 211 // Always restore square braces so we don't break things like <!--[if IE ]> 212 $content = unescape_invalid_shortcodes( $content ); 213 214 return $content; 198 215 } 199 216 … … 289 306 290 307 /** 308 * Search only inside HTML elements for shortcodes and process them. 309 * 310 * Any [ or ] characters remaining inside elements will be HTML encoded 311 * to prevent interference with shortcodes that are outside the elements. 312 * Assumes $content processed by KSES already. Users with unfiltered_html 313 * capability may get unexpected output if angle braces are nested in tags. 314 * 315 * @since 4.2.3 316 * 317 * @param string $content Content to search for shortcodes 318 * @param bool $ignore_html When true, all square braces inside elements will be encoded. 319 * @return string Content with shortcodes filtered out. 320 */ 321 function do_shortcodes_in_html_tags( $content, $ignore_html ) { 322 // Normalize entities in unfiltered HTML before adding placeholders. 323 $trans = array( '[' => '[', ']' => ']' ); 324 $content = strtr( $content, $trans ); 325 $trans = array( '[' => '[', ']' => ']' ); 326 327 $pattern = get_shortcode_regex(); 328 329 $comment_regex = 330 '!' // Start of comment, after the <. 331 . '(?:' // Unroll the loop: Consume everything until --> is found. 332 . '-(?!->)' // Dash not followed by end of comment. 333 . '[^\-]*+' // Consume non-dashes. 334 . ')*+' // Loop possessively. 335 . '(?:-->)?'; // End of comment. If not found, match all input. 336 337 $regex = 338 '/(' // Capture the entire match. 339 . '<' // Find start of element. 340 . '(?(?=!--)' // Is this a comment? 341 . $comment_regex // Find end of comment. 342 . '|' 343 . '[^>]*>?' // Find end of element. If not found, match all input. 344 . ')' 345 . ')/s'; 346 347 $textarr = preg_split( $regex, $content, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY ); 348 349 foreach ( $textarr as &$element ) { 350 if ( '<' !== $element[0] ) { 351 continue; 352 } 353 354 $noopen = false === strpos( $element, '[' ); 355 $noclose = false === strpos( $element, ']' ); 356 if ( $noopen || $noclose ) { 357 // This element does not contain shortcodes. 358 if ( $noopen xor $noclose ) { 359 // Need to encode stray [ or ] chars. 360 $element = strtr( $element, $trans ); 361 } 362 continue; 363 } 364 365 if ( $ignore_html || '<!--' === substr( $element, 0, 4 ) ) { 366 // Encode all [ and ] chars. 367 $element = strtr( $element, $trans ); 368 continue; 369 } 370 371 $attributes = wp_kses_attr_parse( $element ); 372 if ( false === $attributes ) { 373 // Looks like we found some crazy unfiltered HTML. Skipping it for sanity. 374 $element = strtr( $element, $trans ); 375 continue; 376 } 377 378 // Get element name 379 $front = array_shift( $attributes ); 380 $back = array_pop( $attributes ); 381 $matches = array(); 382 preg_match('%[a-zA-Z0-9]+%', $front, $matches); 383 $elname = $matches[0]; 384 385 // Look for shortcodes in each attribute separately. 386 foreach ( $attributes as &$attr ) { 387 $open = strpos( $attr, '[' ); 388 $close = strpos( $attr, ']' ); 389 if ( false === $open || false === $close ) { 390 continue; // Go to next attribute. Square braces will be escaped at end of loop. 391 } 392 $double = strpos( $attr, '"' ); 393 $single = strpos( $attr, "'" ); 394 if ( ( false === $single || $open < $single ) && ( false === $double || $open < $double ) ) { 395 // $attr like '[shortcode]' or 'name = [shortcode]' implies unfiltered_html. 396 // In this specific situation we assume KSES did not run because the input 397 // was written by an administrator, so we should avoid changing the output 398 // and we do not need to run KSES here. 399 $attr = preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $attr ); 400 } else { 401 // $attr like 'name = "[shortcode]"' or "name = '[shortcode]'" 402 // We do not know if $content was unfiltered. Assume KSES ran before shortcodes. 403 $count = 0; 404 $new_attr = preg_replace_callback( "/$pattern/s", 'do_shortcode_tag', $attr, -1, $count ); 405 if ( $count > 0 ) { 406 // Sanitize the shortcode output using KSES. 407 $new_attr = wp_kses_one_attr( $new_attr, $elname ); 408 if ( '' !== $new_attr ) { 409 // The shortcode is safe to use now. 410 $attr = $new_attr; 411 } 412 } 413 } 414 } 415 $element = $front . implode( '', $attributes ) . $back; 416 417 // Now encode any remaining [ or ] chars. 418 $element = strtr( $element, $trans ); 419 } 420 421 $content = implode( '', $textarr ); 422 423 return $content; 424 } 425 426 /** 427 * Remove placeholders added by do_shortcodes_in_html_tags(). 428 * 429 * @since 4.2.3 430 * 431 * @param string $content Content to search for placeholders. 432 * @return string Content with placeholders removed. 433 */ 434 function unescape_invalid_shortcodes( $content ) { 435 // Clean up entire string, avoids re-parsing HTML. 436 $trans = array( '[' => '[', ']' => ']' ); 437 $content = strtr( $content, $trans ); 438 439 return $content; 440 } 441 442 /** 291 443 * Retrieve all attributes from the shortcodes tag. 292 444 * … … 387 539 return $content; 388 540 541 $content = do_shortcodes_in_html_tags( $content, true ); 542 389 543 $pattern = get_shortcode_regex(); 390 391 return preg_replace_callback( "/$pattern/s", 'strip_shortcode_tag', $content ); 544 $content = preg_replace_callback( "/$pattern/s", 'strip_shortcode_tag', $content ); 545 546 // Always restore square braces so we don't break things like <!--[if IE ]> 547 $content = unescape_invalid_shortcodes( $content ); 548 549 return $content; 392 550 } 393 551 -
branches/4.1/tests/phpunit/tests/kses.php
r28942 r33380 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.1/tests/phpunit/tests/shortcode.php
r32147 r33380 387 387 388 388 /** 389 * Check for bugginess using normal input with latest patches. 390 * 391 * @dataProvider data_escaping 392 */ 393 function test_escaping( $input, $output ) { 394 return $this->assertEquals( $output, do_shortcode( $input ) ); 395 } 396 397 function data_escaping() { 398 return array( 399 array( 400 '<!--[if lt IE 7]>', 401 '<!--[if lt IE 7]>', 402 ), 403 array( 404 '[gallery title="<div>hello</div>"]', 405 '', 406 ), 407 array( 408 '[caption caption="test" width="2"]<div>hello</div>[/caption]', 409 '<div style="width: 12px" class="wp-caption alignnone"><div>hello</div><p class="wp-caption-text">test</p></div>', 410 ), 411 array( 412 '<div [gallery]>', 413 '<div >', 414 ), 415 array( 416 '<div [[gallery]]>', 417 '<div [gallery]>', 418 ), 419 array( 420 '[gallery]<div>Hello</div>[/gallery]', 421 '', 422 ), 423 ); 424 } 425 426 /** 427 * Check for bugginess using normal input with latest patches. 428 * 429 * @dataProvider data_escaping2 430 */ 431 function test_escaping2( $input, $output ) { 432 return $this->assertEquals( $output, strip_shortcodes( $input ) ); 433 } 434 435 function data_escaping2() { 436 return array( 437 array( 438 '<!--[if lt IE 7]>', 439 '<!--[if lt IE 7]>', 440 ), 441 array( 442 '[gallery title="<div>hello</div>"]', 443 '', 444 ), 445 array( 446 '[caption caption="test" width="2"]<div>hello</div>[/caption]', 447 '', 448 ), 449 array( 450 '<div [gallery]>', // Shortcodes will never be stripped inside elements. 451 '<div [gallery]>', 452 ), 453 array( 454 '<div [[gallery]]>', // Shortcodes will never be stripped inside elements. 455 '<div [[gallery]]>', 456 ), 457 array( 458 '[gallery]<div>Hello</div>[/gallery]', 459 '', 460 ), 461 ); 462 } 463 464 /** 389 465 * @ticket 26343 390 466 */
Note: See TracChangeset
for help on using the changeset viewer.