Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Add processing directives without namespace and with empty namespace #6262

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ private function data_wp_interactive_processor( WP_Interactivity_API_Directives_
* independently of whether the previous `data-wp-interactive` definition
* contained a valid namespace.
*/
$new_namespace = null;
$new_namespace = 'WP';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify how this change fixes the problem? Difficult to understand from looking at the surrounding code, and it seems such a simple change. To be fair, I'm not very familiar with the underlying code :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How does this change impact accessing the context on the client?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should change the impact, rather than anyone can access namespaces not defined with this default one.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you clarify how this change fixes the problem? Difficult to understand from looking at the surrounding code, and it seems such a simple change. To be fair, I'm not very familiar with the underlying code :)

The directives were not being processed cause they expected non empty string as a namespace. While reading the data-wp-interactive attribute, we are returning a boolean in case is not defined data-wp-interactive or an empty string.

Adding a default one would fix it (my tests are running OK in local, not here 🤔 ), but it is not a good solution. That's why I wanted to check with @DAreRodz too 😅

if ( is_string( $attribute_value ) && ! empty( $attribute_value ) ) {
$decoded_json = json_decode( $attribute_value, true );
if ( is_array( $decoded_json ) ) {
Expand Down
52 changes: 52 additions & 0 deletions tests/phpunit/tests/interactivity-api/wpInteractivityAPI.php
Original file line number Diff line number Diff line change
Expand Up @@ -772,4 +772,56 @@ public function test_kebab_to_camel_case() {
$this->assertSame( 'myItem', $method->invoke( $this->interactivity, 'my-item-' ) );
$this->assertSame( 'myItem', $method->invoke( $this->interactivity, '-my-item-' ) );
}

/**
* Tests that directives are processed if
* data-wp-interactive has no value.
*
* @ticket
*
* @covers process_directives
*/
public function test_process_directives_process_the_directives_without_namespace() {
$html = '
<input
id="some-id"
data-wp-interactive
' . wp_interactivity_data_wp_context(
array(
'id' => 'some-id',
)
) . '
data-wp-bind--value="context.id"
/>';
$processed_html = $this->interactivity->process_directives( $html );
$p = new WP_HTML_Tag_Processor( $processed_html );
$p->next_tag( array( 'id', 'some-id' ) );
$this->assertEquals( 'some-id', $p->get_attribute( 'value' ) );
}

/**
* Tests that directives are processed if
* data-wp-interactive is an empty string.
*
* @ticket
*
* @covers process_directives
*/
public function test_process_directives_process_the_directives_with_empty_namespace() {
$html = '
<input
id="some-id"
data-wp-interactive=""
' . wp_interactivity_data_wp_context(
array(
'id' => 'some-id',
)
) . '
data-wp-bind--value="context.id"
/>';
$processed_html = $this->interactivity->process_directives( $html );
$p = new WP_HTML_Tag_Processor( $processed_html );
$p->next_tag( array( 'id', 'some-id' ) );
$this->assertEquals( 'some-id', $p->get_attribute( 'value' ) );
}
}