Skip to content
This repository was archived by the owner on Feb 23, 2024. It is now read-only.

Commit 769f9c6

Browse files
oprAljullu
andauthored
Strip tags from exceptions that are converted from notices (#4005)
* Strip tags that are added to notices * Add test to ensure HTML is stripped by convert_notices_to_exceptions * Test function directly, rather than through validate_cart_items * Apply correct formatting to tests/php/StoreApi/Utilities/NoticeHandler.php Co-authored-by: Albert Juhé Lluveras <[email protected]> Co-authored-by: Albert Juhé Lluveras <[email protected]>
1 parent 8c1931e commit 769f9c6

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/StoreApi/Utilities/NoticeHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public static function convert_notices_to_exceptions( $error_code = 'unknown_ser
3434
wc_clear_notices();
3535

3636
foreach ( $error_notices as $error_notice ) {
37-
throw new RouteException( $error_code, $error_notice['notice'], 400 );
37+
throw new RouteException( $error_code, wp_strip_all_tags( $error_notice['notice'] ), 400 );
3838
}
3939
}
4040
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
/**
3+
* NoticeHandler Tests.
4+
*/
5+
6+
namespace Automattic\WooCommerce\Blocks\Tests\StoreApi\Utilities;
7+
8+
use Automattic\WooCommerce\Blocks\StoreApi\Routes\RouteException;
9+
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\CartController;
10+
use Automattic\WooCommerce\Blocks\StoreApi\Utilities\NoticeHandler;
11+
use PHPUnit\Framework\TestCase;
12+
use \WC_Helper_Product as ProductHelper;
13+
14+
class NoticeHandlerTests extends TestCase {
15+
16+
public function test_convert_notices_to_exceptions() {
17+
$this->expectException( RouteException::class );
18+
$this->expectExceptionMessage( 'This is an error message with Some HTML in it.' );
19+
wc_add_notice( '<strong>This is an error message with <a href="#">Some HTML in it</a>.', 'error' );
20+
$errors = NoticeHandler::convert_notices_to_exceptions( 'test_error' );
21+
}
22+
}

0 commit comments

Comments
 (0)