Skip to content

Commit 67749d9

Browse files
committed
Fix double escaping
1 parent 1341c1e commit 67749d9

File tree

3 files changed

+23
-33
lines changed

3 files changed

+23
-33
lines changed

includes/MslsAdmin.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ public function __call( $method, $args ) {
126126
*
127127
* @return bool
128128
*/
129-
public function has_problems(): bool {
129+
public function has_problems(): void {
130130
$message = '';
131131

132132
if ( $this->options->is_empty() ) {
@@ -148,7 +148,7 @@ public function has_problems(): bool {
148148
);
149149
}
150150

151-
return MslsPlugin::message_handler( $message, 'updated fade' );
151+
MslsPlugin::message_handler( $message, 'updated fade' );
152152
}
153153

154154
/**

includes/MslsPlugin.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,13 @@ public function init_i18n_support(): void {
190190
*/
191191
public static function message_handler( $message, $css_class = 'error' ) {
192192
if ( ! empty( $message ) ) {
193-
printf( '<div id="msls-warning" class="%s"><p>%s</p></div>', esc_attr( $css_class ), esc_html( $message ) );
193+
echo wp_kses_post(
194+
sprintf(
195+
'<div id="msls-warning" class="%s"><p>%s</p></div>',
196+
esc_attr( $css_class ),
197+
$message
198+
)
199+
);
194200

195201
return true;
196202
}

tests/phpunit/TestMslsAdmin.php

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -60,47 +60,31 @@ public function get_sut( array $users = array() ): MslsAdmin {
6060
return new MslsAdmin( $options, $collection );
6161
}
6262

63-
public function test_has_problems_no_problem(): void {
64-
$options = \Mockery::mock( MslsOptions::class );
65-
$options->shouldReceive( 'get_available_languages' )->andReturns( array( 'de_DE', 'it_IT' ) );
66-
67-
$collection = \Mockery::mock( MslsBlogCollection::class );
68-
$options->shouldReceive( 'is_empty' )->andReturns( false );
69-
70-
$obj = new MslsAdmin( $options, $collection );
71-
72-
$this->assertFalse( $obj->has_problems() );
73-
}
74-
75-
public function test_has_problems_one_language(): void {
76-
$options = \Mockery::mock( MslsOptions::class );
77-
$options->shouldReceive( 'get_available_languages' )->andReturns( array( 'de_DE' ) );
78-
79-
$collection = \Mockery::mock( MslsBlogCollection::class );
80-
$options->shouldReceive( 'is_empty' )->andReturns( false );
81-
82-
$obj = new MslsAdmin( $options, $collection );
83-
84-
$this->expectOutputRegex( '/^<div id="msls-warning" class="updated fade"><p>.*$/' );
85-
86-
$this->assertTrue( $obj->has_problems() );
63+
public static function has_problems_data(): array {
64+
return array(
65+
array( array( 'de_DE', 'it_IT' ), false, '/^$/' ),
66+
array( array( 'de_DE' ), false, '/^<div id="msls-warning" class="updated fade"><p>.*$/' ),
67+
array( array(), true, '/^<div id="msls-warning" class="updated fade"><p>.*$/' ),
68+
);
8769
}
8870

89-
public function test_has_problems_is_empty(): void {
71+
/**
72+
* @dataProvider has_problems_data
73+
*/
74+
public function test_has_problems( array $languages, bool $is_empty, string $regex ): void {
9075
Functions\when( 'get_option' )->justReturn( array() );
9176
Functions\when( 'get_current_blog_id' )->justReturn( 1 );
9277
Functions\when( 'admin_url' )->justReturn( '' );
9378

9479
$options = \Mockery::mock( MslsOptions::class );
95-
$options->shouldReceive( 'is_empty' )->andReturns( true );
80+
$options->shouldReceive( 'get_available_languages' )->zeroOrMoreTimes()->andReturns( $languages );
9681

9782
$collection = \Mockery::mock( MslsBlogCollection::class );
83+
$options->shouldReceive( 'is_empty' )->once()->andReturns( $is_empty );
9884

99-
$obj = new MslsAdmin( $options, $collection );
100-
101-
$this->expectOutputRegex( '/^<div id="msls-warning" class="updated fade"><p>.*$/' );
85+
$this->expectOutputRegex( $regex );
10286

103-
$this->assertTrue( $obj->has_problems() );
87+
( new MslsAdmin( $options, $collection ) )->has_problems();
10488
}
10589

10690
public function test_subsubsub(): void {

0 commit comments

Comments
 (0)