Changeset 58321
- Timestamp:
- 06/04/2024 07:16:48 AM (2 months ago)
- Location:
- trunk
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/interactivity-api/class-wp-interactivity-api-directives-processor.php
r58233 r58321 199 199 $depth = 1; 200 200 $tag_name = $this->get_tag(); 201 while ( $depth > 0 && $this->next_tag( 202 array( 203 'tag_name' => $tag_name, 204 'tag_closers' => 'visit', 205 ) 206 ) ) { 207 if ( $this->has_self_closing_flag() ) { 208 continue; 209 } 210 $depth += $this->is_tag_closer() ? -1 : 1; 201 202 while ( $depth > 0 && $this->next_tag( array( 'tag_closers' => 'visit' ) ) ) { 203 if ( ! $this->is_tag_closer() && $this->get_attribute_names_with_prefix( 'data-wp-' ) ) { 204 /* translators: 1: SVG or MATH HTML tag. */ 205 $message = sprintf( __( 'Interactivity directives were detected inside an incompatible %1$s tag. These directives will be ignored in the server side render.' ), $tag_name ); 206 _doing_it_wrong( __METHOD__, $message, '6.6.0' ); 207 } 208 if ( $this->get_tag() === $tag_name ) { 209 if ( $this->has_self_closing_flag() ) { 210 continue; 211 } 212 $depth += $this->is_tag_closer() ? -1 : 1; 213 } 211 214 } 212 215 -
trunk/src/wp-includes/interactivity-api/class-wp-interactivity-api.php
r58320 r58321 273 273 * 274 274 * @since 6.5.0 275 275 276 * 276 277 * @param string $html The HTML content to process. … … 296 297 */ 297 298 if ( 'SVG' === $tag_name || 'MATH' === $tag_name ) { 299 300 301 302 303 298 304 $p->skip_to_tag_closer(); 299 305 continue; … … 383 389 } 384 390 } 385 386 391 /* 387 392 * It returns null if the HTML is unbalanced because unbalanced HTML is 388 393 * not safe to process. In that case, the Interactivity API runtime will 389 * update the HTML on the client side during the hydration. 394 * update the HTML on the client side during the hydration. It will also 395 * display a notice to the developer to inform them about the issue. 390 396 */ 391 return $unbalanced || 0 < count( $tag_stack ) ? null : $p->get_updated_html(); 397 if ( $unbalanced || 0 < count( $tag_stack ) ) { 398 $tag_errored = 0 < count( $tag_stack ) ? end( $tag_stack )[0] : $tag_name; 399 /* translators: %1s: Namespace processed, %2s: The tag that caused the error; could be any HTML tag. */ 400 $message = sprintf( __( 'Interactivity directives failed to process in "%1$s" due to a missing "%2$s" end tag.' ), end( $namespace_stack ), $tag_errored ); 401 _doing_it_wrong( __METHOD__, $message, '6.6.0' ); 402 return null; 403 } 404 405 return $p->get_updated_html(); 392 406 } 393 407 … … 397 411 * 398 412 * @since 6.5.0 413 399 414 * 400 415 * @param string|true $directive_value The directive attribute value string or `true` when it's a boolean attribute. … … 403 418 * @param array|false $context The current context for evaluating the directive or false if there is no 404 419 * context. 405 * @return mixed|null The result of the evaluation. Null if the reference path doesn't exist .420 * @return mixed|null The result of the evaluation. Null if the reference path doesn't exist. 406 421 */ 407 422 private function evaluate( $directive_value, string $default_namespace, $context = false ) { 408 423 list( $ns, $path ) = $this->extract_directive_value( $directive_value, $default_namespace ); 409 if ( empty( $path ) ) { 424 if ( ! $ns || ! $path ) { 425 /* translators: %s: The directive value referenced. */ 426 $message = sprintf( __( 'Namespace or reference path cannot be empty. Directive value referenced: %s' ), $directive_value ); 427 _doing_it_wrong( __METHOD__, $message, '6.6.0' ); 410 428 return null; 411 429 } -
trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-bind.php
r57836 r58321 155 155 * 156 156 * @covers ::process_directives 157 157 158 */ 158 159 public function test_wp_bind_ignores_empty_value() { … … 168 169 * 169 170 * @covers ::process_directives 171 170 172 */ 171 173 public function test_wp_bind_ignores_without_value() { -
trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-class.php
r57836 r58321 238 238 * 239 239 * @covers ::process_directives 240 240 241 */ 241 242 public function test_wp_class_doesnt_change_class_attribute_with_empty_value() { … … 252 253 * 253 254 * @covers ::process_directives 255 254 256 */ 255 257 public function test_wp_class_doesnt_change_class_attribute_without_value() { -
trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-context.php
r57836 r58321 318 318 * 319 319 * @covers ::process_directives 320 320 321 */ 321 322 public function test_wp_context_directive_doesnt_work_without_any_namespace() { -
trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-each.php
r57836 r58321 581 581 * 582 582 * @covers ::process_directives 583 584 583 585 */ 584 586 public function test_wp_each_unbalanced_tags() { … … 599 601 * 600 602 * @covers ::process_directives 603 604 601 605 */ 602 606 public function test_wp_each_unbalanced_tags_in_nested_template_tags() { -
trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-style.php
r57836 r58321 366 366 * 367 367 * @covers ::process_directives 368 368 369 */ 369 370 public function test_wp_style_doesnt_change_style_attribute_with_empty_value() { … … 380 381 * 381 382 * @covers ::process_directives 383 382 384 */ 383 385 public function test_wp_style_doesnt_change_style_attribute_without_value() { -
trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI-wp-text.php
r57836 r58321 13 13 * @group interactivity-api 14 14 */ 15 class Tests_ WP_Interactivity_API_WP_Text extends WP_UnitTestCase {15 class Tests_Text extends WP_UnitTestCase { 16 16 /** 17 17 * Instance of WP_Interactivity_API. … … 132 132 * 133 133 * @covers ::process_directives 134 135 134 136 */ 135 137 public function test_wp_text_fails_with_unbalanced_and_same_tags_inside_content() { -
trunk/tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php
r58320 r58321 650 650 * @dataProvider data_html_with_unbalanced_tags 651 651 * 652 653 652 654 * @param string $html HTML containing unbalanced tags and also a directive. 653 655 */ … … 697 699 $html = ' 698 700 <header> 699 <svg height="100" data-wp-bind--width="myPlugin::state.width">701 <svg height="100"> 700 702 <title>Red Circle</title> 701 703 <circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" /> 702 704 </svg> 703 705 <div data-wp-bind--id="myPlugin::state.id"></div> 704 <div data-wp-bind--id="myPlugin::state.width"></div>705 706 </header> 706 707 '; 707 708 $processed_html = $this->interactivity->process_directives( $html ); 708 709 $p = new WP_HTML_Tag_Processor( $processed_html ); 709 $p->next_tag( 'svg' );710 $this->assertNull( $p->get_attribute( 'width' ) );711 710 $p->next_tag( 'div' ); 712 711 $this->assertEquals( 'some-id', $p->get_attribute( 'id' ) ); 713 $p->next_tag( 'div' );714 $this->assertEquals( '100', $p->get_attribute( 'id' ) );715 712 } 716 713 … … 722 719 * 723 720 * @covers ::process_directives 721 724 722 */ 725 723 public function test_process_directives_does_not_change_inner_html_in_svgs() { … … 751 749 * 752 750 * @covers ::process_directives 751 753 752 */ 754 753 public function test_process_directives_change_html_if_contains_math() { … … 785 784 * 786 785 * @covers ::process_directives 786 787 787 788 */ 788 789 public function test_process_directives_does_not_change_inner_html_in_math() { … … 812 813 * Invokes the private `evaluate` method of WP_Interactivity_API class. 813 814 * 814 * @param string $directive_value The directive attribute value to evaluate. 815 * @param string $directive_value The directive attribute value to evaluate. 816 * @param string $default_namespace The default namespace used with directives. 815 817 * @return mixed The result of the evaluate method. 816 818 */ 817 private function evaluate( $directive_value ) {819 private function evaluate( $directive_value ) { 818 820 $generate_state = function ( $name ) { 819 821 $obj = new stdClass(); … … 848 850 $evaluate = new ReflectionMethod( $this->interactivity, 'evaluate' ); 849 851 $evaluate->setAccessible( true ); 850 return $evaluate->invokeArgs( $this->interactivity, array( $directive_value, 'myPlugin', $context ) );852 return $evaluate->invokeArgs( $this->interactivity, array( $directive_value, , $context ) ); 851 853 } 852 854 … … 946 948 $result = $this->evaluate( 'otherPlugin::context.nested.key' ); 947 949 $this->assertEquals( 'otherPlugin-context-nested', $result ); 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 948 969 } 949 970
Note: See TracChangeset
for help on using the changeset viewer.