Skip to content
This repository has been archived by the owner on Jul 28, 2023. It is now read-only.

Commit

Permalink
Add escaping to wp-text
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Mar 15, 2023
1 parent 28f58ac commit 96c5ca1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions phpunit/directives/attributes/wp-text.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@
* @covers process_wp_text
*/
class Tests_Directives_WpText extends WP_UnitTestCase {
public function test_directive_sets_inner_html_based_on_attribute_value() {
public function test_directive_sets_inner_html_based_on_attribute_value_and_escapes_html() {
$markup = '<div wp-text="context.myblock.someText"></div>';

$tags = new WP_Directive_Processor( $markup );
$tags->next_tag();

$context_before = new WP_Directive_Context( array( 'myblock' => array( 'someText' => 'Lorem ipsum dolor sit.' ) ) );
$context_before = new WP_Directive_Context( array( 'myblock' => array( 'someText' => 'The HTML tag <br> produces a line break.' ) ) );
$context = clone $context_before;
process_wp_text( $tags, $context );

$expected_markup = '<div wp-text="context.myblock.someText">Lorem ipsum dolor sit.</div>';
$expected_markup = '<div wp-text="context.myblock.someText">The HTML tag &lt;br&gt; produces a line break.</div>';
$this->assertSame( $expected_markup, $tags->get_updated_html() );
$this->assertSame( $context_before->get_context(), $context->get_context(), 'wp-text directive changed context' );
}
Expand Down
2 changes: 1 addition & 1 deletion src/directives/attributes/wp-text.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ function process_wp_text( $tags, $context ) {
}

$text = evaluate( $value, $context->get_context() );
$tags->set_inner_html( $text );
$tags->set_inner_html( esc_html( $text ) );
}

0 comments on commit 96c5ca1

Please sign in to comment.