Changeset 65790
- Timestamp:
- 11/25/2026 07:33:37 PM (12 hours ago)
- Location:
- trunk
- Files:
-
- 3 edited
-
src/wp-includes/class-wp-text-diff-renderer-table.php (modified) (3 diffs)
-
src/wp-includes/pluggable.php (modified) (2 diffs)
-
tests/phpunit/tests/diff/wpTextDiffRendererTable.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/class-wp-text-diff-renderer-table.php
r62649 r65790 67 67 */ 68 68 protected $_diff_threshold = 0.6; 69 70 /** 71 * Maximum line length in bytes for word-level highlighting. 72 * 73 * @since 7.3.0 74 * @var int 75 */ 76 protected $_max_word_diff_line_length = 10000; 77 78 /** 79 * Maximum number of line pairs to compare when matching changed lines. 80 * 81 * @since 7.3.0 82 * @var int 83 */ 84 protected $_max_changed_line_pairs = 250000; 85 86 /** 87 * Maximum total number of old and new lines to match in a changed block. 88 * 89 * @since 7.3.0 90 * @var int 91 */ 92 protected $_max_changed_lines = 5000; 69 93 70 94 /** … … 286 310 */ 287 311 public function _changed( $orig, $final ) { // phpcs:ignore Universal.NamingConventions.NoReservedKeywordParameterNames.finalFound 312 $old_count = count( $orig ); 313 $new_count = count( $final ); 314 // interleave_changed_lines() scores every old line against every new line. 315 if ( $old_count + $new_count > $this->_max_changed_lines 316 || $old_count * $new_count > $this->_max_changed_line_pairs 317 ) { 318 return $this->_deleted( $orig ) . $this->_added( $final ); 319 } 320 288 321 $r = ''; 289 322 … … 306 339 foreach ( $orig_matches as $o => $f ) { 307 340 if ( is_numeric( $o ) && is_numeric( $f ) ) { 341 if ( strlen( $orig[ $o ] ) > $this->_max_word_diff_line_length 342 || strlen( $final[ $f ] ) > $this->_max_word_diff_line_length 343 ) { 344 continue; 345 } 346 308 347 $text_diff = new Text_Diff( 'auto', array( array( $orig[ $o ] ), array( $final[ $f ] ) ) ); 309 348 $renderer = new $this->inline_diff_renderer(); -
trunk/src/wp-includes/pluggable.php
r65788 r65790 3412 3412 * 3413 3413 * @since 2.6.0 3414 * @since 7.3.0 Added the `$max_word_diff_line_length`, `$max_changed_lines`, 3415 * and `$max_changed_line_pairs` arguments. 3414 3416 * 3415 3417 * @see wp_parse_args() Used to change defaults to user defined settings. … … 3422 3424 * Associative array of options to pass to WP_Text_Diff_Renderer_Table(). 3423 3425 * 3424 * @type string $title Titles the diff in a manner compatible 3425 * with the output. Default empty. 3426 * @type string $title_left Change the HTML to the left of the title. 3427 * Default empty. 3428 * @type string $title_right Change the HTML to the right of the title. 3429 * Default empty. 3430 * @type bool $show_split_view True for split view (two columns), false for 3431 * un-split view (single column). Default true. 3426 * @type string $title Titles the diff in a manner compatible 3427 * with the output. Default empty. 3428 * @type string $title_left Change the HTML to the left of the title. 3429 * Default empty. 3430 * @type string $title_right Change the HTML to the right of the title. 3431 * Default empty. 3432 * @type bool $show_split_view True for split view (two columns), false for 3433 * un-split view (single column). Default true. 3434 * @type int $max_word_diff_line_length Changed lines longer than this many bytes get 3435 * no word-level highlighting. Default 10000. 3436 * @type int $max_changed_lines A changed block with more old and new lines 3437 * than this shows removed lines, then added 3438 * lines. Default 5000. 3439 * @type int $max_changed_line_pairs A changed block with more old-by-new line 3440 * pairs than this shows removed lines, then 3441 * added lines. Default 250000. 3432 3442 * } 3433 3443 * @return string Empty string if strings are equivalent or HTML with differences. -
trunk/tests/phpunit/tests/diff/wpTextDiffRendererTable.php
r65033 r65790 14 14 public static function set_up_before_class() { 15 15 parent::set_up_before_class(); 16 require_once ABSPATH . 'wp-includes/Text/Diff.php'; 16 17 require_once ABSPATH . 'wp-includes/Text/Diff/Renderer.php'; 18 require_once ABSPATH . 'wp-includes/Text/Diff/Renderer/inline.php'; 17 19 require_once ABSPATH . 'wp-includes/class-wp-text-diff-renderer-table.php'; 20 require_once ABSPATH . 'wp-includes/class-wp-text-diff-renderer-inline.php'; 18 21 } 19 22 … … 21 24 parent::set_up(); 22 25 $this->diff_renderer_table = new WP_Text_Diff_Renderer_Table(); 26 } 27 28 /** 29 * @ticket 66095 30 * @ticket 48973 31 * @covers WP_Text_Diff_Renderer_Table::_changed 32 * @dataProvider data_changed_block_limits 33 * 34 * @param string $limit Name of the limit argument. 35 * @param int $value Limit that the 3 old and 3 new lines exceed. 36 */ 37 public function test_changed_lists_deletions_before_additions_above_a_block_limit( $limit, $value ) { 38 $renderer = $this->diff_renderer_table; 39 $old = array( 'alpha & old', 'bravo & old', 'charlie & old' ); 40 $new = array( 'alpha & new', 'bravo & new', 'charlie & new' ); 41 $fallback = $renderer->_deleted( $old ) . $renderer->_added( $new ); 42 43 $this->assertNotSame( $fallback, $renderer->_changed( $old, $new ) ); 44 45 $limited = new WP_Text_Diff_Renderer_Table( array( $limit => $value ) ); 46 $this->assertSame( $fallback, $limited->_changed( $old, $new ) ); 47 } 48 49 /** 50 * Data provider for test_changed_lists_deletions_before_additions_above_a_block_limit(). 51 * 52 * @return array 53 */ 54 public static function data_changed_block_limits() { 55 return array( 56 'line pairs' => array( 'max_changed_line_pairs', 8 ), 57 'lines' => array( 'max_changed_lines', 5 ), 58 ); 59 } 60 61 /** 62 * @ticket 66095 63 * @covers WP_Text_Diff_Renderer_Table::_changed 64 * @dataProvider data_long_line_pairs 65 * 66 * @param string $old_line Old line. 67 * @param string $new_line New line. 68 */ 69 public function test_changed_skips_word_highlighting_when_a_line_exceeds_the_length_limit( $old_line, $new_line ) { 70 $renderer = $this->diff_renderer_table; 71 72 $this->assertSame( 73 '<tr>' . $renderer->deletedLine( str_replace( '&', '&', $old_line ) ) . $renderer->addedLine( str_replace( '&', '&', $new_line ) ) . "</tr>\n", 74 $renderer->_changed( array( $old_line ), array( $new_line ) ) 75 ); 76 } 77 78 /** 79 * Data provider for test_changed_skips_word_highlighting_when_a_line_exceeds_the_length_limit(). 80 * 81 * @return array 82 */ 83 public static function data_long_line_pairs() { 84 $short = str_repeat( 'x', 9000 ) . '&old'; 85 $long = str_repeat( 'x', 9000 ) . '&' . str_repeat( 'y', 2999 ); 86 87 return array( 88 'long old line' => array( $long, $short ), 89 'long new line' => array( $short, $long ), 90 ); 91 } 92 93 /** 94 * @ticket 66095 95 * @covers ::wp_text_diff 96 */ 97 public function test_wp_text_diff_limits_can_be_raised_through_args() { 98 $old = str_repeat( 'x', 12000 ) . ' old'; 99 $new = str_repeat( 'x', 12000 ) . ' new'; 100 101 $this->assertStringNotContainsString( '<del>old</del>', wp_text_diff( $old, $new ) ); 102 $this->assertStringContainsString( '<del>old</del>', wp_text_diff( $old, $new, array( 'max_word_diff_line_length' => 20000 ) ) ); 23 103 } 24 104
Note:
See TracChangeset
for help on using the changeset viewer.