Ticket #10377: 10377.5.diff
File 10377.5.diff, 8.9 KB (added by , 9 years ago) |
---|
-
src/wp-includes/comment-template.php
2099 2099 $html5 = 'html5' === $args['format']; 2100 2100 $fields = array( 2101 2101 'author' => '<p class="comment-form-author">' . '<label for="author">' . __( 'Name' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . 2102 '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" ' . $aria_req . $html_req . ' /></p>',2102 '<input id="author" name="author" type="text" value="' . esc_attr( $commenter['comment_author'] ) . '" size="30" maxlength="245"' . $aria_req . $html_req . ' /></p>', 2103 2103 'email' => '<p class="comment-form-email"><label for="email">' . __( 'Email' ) . ( $req ? ' <span class="required">*</span>' : '' ) . '</label> ' . 2104 '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" aria-describedby="email-notes"' . $aria_req . $html_req . ' /></p>',2104 '<input id="email" name="email" ' . ( $html5 ? 'type="email"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_email'] ) . '" size="30" maxlength="100" aria-describedby="email-notes"' . $aria_req . $html_req . ' /></p>', 2105 2105 'url' => '<p class="comment-form-url"><label for="url">' . __( 'Website' ) . '</label> ' . 2106 '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" /></p>',2106 '<input id="url" name="url" ' . ( $html5 ? 'type="url"' : 'type="text"' ) . ' value="' . esc_attr( $commenter['comment_author_url'] ) . '" size="30" maxlength="200" /></p>', 2107 2107 ); 2108 2108 2109 2109 $required_text = sprintf( ' ' . __('Required fields are marked %s'), '<span class="required">*</span>' ); … … 2118 2118 $fields = apply_filters( 'comment_form_default_fields', $fields ); 2119 2119 $defaults = array( 2120 2120 'fields' => $fields, 2121 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" aria-required="true" required="required"></textarea></p>',2121 'comment_field' => '<p class="comment-form-comment"><label for="comment">' . _x( 'Comment', 'noun' ) . '</label> <textarea id="comment" name="comment" cols="45" rows="8" maxlength="65525" aria-required="true" required="required"></textarea></p>', 2122 2122 /** This filter is documented in wp-includes/link-template.php */ 2123 2123 'must_log_in' => '<p class="must-log-in">' . sprintf( __( 'You must be <a href="%s">logged in</a> to post a comment.' ), wp_login_url( apply_filters( 'the_permalink', get_permalink( $post_id ) ) ) ) . '</p>', 2124 2124 /** This filter is documented in wp-includes/link-template.php */ -
src/wp-includes/comment.php
948 948 } 949 949 950 950 /** 951 * Calculate the maximum character length of a column from the comments table. 952 * 953 * @since 4.5.0 954 * 955 * @global wpdb $wpdb WordPress database abstraction object. 956 * 957 * @param string $column Name of a column in the comments table. 958 * @return int Maximum column character length. 959 */ 960 function wp_get_comment_column_max_length( $column ) { 961 global $wpdb; 962 963 $col_length = $wpdb->get_col_length( $wpdb->comments, $column ); 964 if ( ! is_array( $col_length ) && (int) $col_length > 0 ) { 965 $max_length = (int) $col_length; 966 } elseif ( is_array( $col_length ) && isset( $col_length['length'] ) && intval( $col_length['length'] ) > 0 ) { 967 $max_length = (int) $col_length['length']; 968 } else { 969 $max_length = 255; 970 } 971 972 if ( ! empty( $col_length['type'] && 'byte' === $col_length['type'] ) ) { 973 $max_length = $max_length - 10; 974 } 975 976 /** 977 * Filters the calculated length for a given column of the comments table. 978 * 979 * @since 4.5.0 980 * 981 * @param int $max_length Maximum column character length. 982 * @param string $column Column name. 983 */ 984 return apply_filters( 'wp_get_comment_column_max_length', $max_length, $column ); 985 } 986 987 /** 951 988 * Does comment contain blacklisted characters or words. 952 989 * 953 990 * @since 1.5.0 … … 2778 2815 } 2779 2816 } 2780 2817 2818 if ( isset( $comment_author ) && wp_get_comment_column_max_length( 'comment_author' ) < mb_strlen( $comment_author, '8bit' ) ) { 2819 return new WP_Error( 'comment_author_column_length', __( '<strong>ERROR</strong>: your name is too long.' ), 200 ); 2820 } 2821 2822 if ( isset( $comment_author_email ) && wp_get_comment_column_max_length( 'comment_author_email' ) < strlen( $comment_author_email ) ) { 2823 return new WP_Error( 'comment_author_email_column_length', __( '<strong>ERROR</strong>: your email address is too long.' ), 200 ); 2824 } 2825 2826 if ( isset( $comment_author_url ) && wp_get_comment_column_max_length( 'comment_author_url' ) < strlen( $comment_author_url ) ) { 2827 return new WP_Error( 'comment_author_url_column_length', __( '<strong>ERROR</strong>: your url is too long.' ), 200 ); 2828 } 2829 2781 2830 if ( '' == $comment_content ) { 2782 2831 return new WP_Error( 'require_valid_comment', __( '<strong>ERROR</strong>: please type a comment.' ), 200 ); 2832 } elseif ( wp_get_comment_column_max_length( 'comment_content' ) < mb_strlen( $comment_content, '8bit' ) ) { 2833 return new WP_Error( 'comment_content_column_length', __( '<strong>ERROR</strong>: your comment is too long.' ), 200 ); 2783 2834 } 2784 2835 2785 2836 $commentdata = compact( -
tests/phpunit/includes/utils.php
6 6 return substr(md5(uniqid(rand())), 0, $len); 7 7 } 8 8 9 function rand_long_str( $length ) { 10 $chars = 'abcdefghijklmnopqrstuvwxyz'; 11 $string = ''; 12 13 for ( $i = 0; $i < $length; $i++ ) { 14 $rand = rand( 0, strlen( $chars ) - 1 ); 15 $string .= substr( $chars, $rand, 1 ); 16 } 17 18 return $string; 19 } 20 9 21 // strip leading and trailing whitespace from each line in the string 10 22 function strip_ws($txt) { 11 23 $lines = explode("\n", $txt); -
tests/phpunit/tests/comment-submission.php
593 593 } 594 594 595 595 /** 596 * @ticket 10377 597 */ 598 public function test_submitting_comment_with_content_too_long_returns_error() { 599 $error = 'comment_content_column_length'; 600 601 $post = self::factory()->post->create_and_get(); 602 603 $data = array( 604 'comment_post_ID' => $post->ID, 605 'comment' => rand_long_str( 65536 ), 606 'author' => 'Comment Author', 607 'email' => 'comment@example.org', 608 ); 609 $comment = wp_handle_comment_submission( $data ); 610 611 $this->assertWPError( $comment ); 612 $this->assertSame( $error, $comment->get_error_code() ); 613 } 614 615 /** 616 * @ticket 10377 617 */ 618 public function test_submitting_comment_with_author_too_long_returns_error() { 619 $error = 'comment_author_column_length'; 620 621 $post = self::factory()->post->create_and_get(); 622 623 $data = array( 624 'comment_post_ID' => $post->ID, 625 'comment' => rand_str(), 626 'author' => rand_long_str( 255 ), 627 'email' => 'comment@example.org', 628 ); 629 $comment = wp_handle_comment_submission( $data ); 630 631 $this->assertWPError( $comment ); 632 $this->assertSame( $error, $comment->get_error_code() ); 633 } 634 635 /** 636 * @ticket 10377 637 */ 638 public function test_submitting_comment_with_email_too_long_returns_error() { 639 $error = 'comment_author_email_column_length'; 640 641 $post = self::factory()->post->create_and_get(); 642 643 $data = array( 644 'comment_post_ID' => $post->ID, 645 'comment' => rand_str(), 646 'author' => 'Comment Author', 647 'email' => rand_long_str( 90 ) . '@example.com', 648 ); 649 $comment = wp_handle_comment_submission( $data ); 650 651 $this->assertWPError( $comment ); 652 $this->assertSame( $error, $comment->get_error_code() ); 653 } 654 655 /** 656 * @ticket 10377 657 */ 658 public function test_submitting_comment_with_url_too_long_returns_error() { 659 $error = 'comment_author_url_column_length'; 660 661 $post = self::factory()->post->create_and_get(); 662 $data = array( 663 'comment_post_ID' => $post->ID, 664 'comment' => rand_str(), 665 'author' => 'Comment Author', 666 'email' => 'comment@example.org', 667 'url' => rand_long_str( 201 ), 668 ); 669 $comment = wp_handle_comment_submission( $data ); 670 671 $this->assertWPError( $comment ); 672 $this->assertSame( $error, $comment->get_error_code() ); 673 } 674 675 /** 596 676 * @ticket 34997 597 677 */ 598 678 public function test_comment_submission_sends_all_expected_parameters_to_preprocess_comment_filter() {