/', function ( $matches ) { $json = str_replace( '\\u005c', '\\\\', $matches[2] ); return ""; }, $input ); } /** * Tests that running the serialised block content through KSES doesn't cause the * HTML to change. * * @dataProvider data_block_fixtures */ public function test_kses_doesnt_change_fixtures( $block, $filename ) { // KSES doesn't allow data: URLs, so we need to replace any of them in fixtures. $block = preg_replace( "/src=['\"]data:[^'\"]+['\"]/", 'src="https://wordpress.org/foo.jpg"', $block ); $block = preg_replace( "/href=['\"]data:[^'\"]+['\"]/", 'href="https://wordpress.org/foo.jpg"', $block ); $block = preg_replace( '/url\(data:[^)]+\)/', 'url(https://wordpress.org/foo.jpg)', $block ); // Account for a wp-env override using a port other than 8889 for the tests environment. $block = preg_replace( '#http://localhost:\d+/#', home_url( '/' ), $block ); $kses_block = wp_kses_post( $block ); // KSES removes the last semi-colon from style attributes, remove it from the original to match. $block = preg_replace( '/style="([^"]*);"/', 'style="$1"', $block ); $this->assertEqualHTML( $block, $kses_block, '', "Failed to match $filename" ); } public function data_block_fixtures() { $data = array(); foreach ( glob( gutenberg_dir_path() . 'test/integration/fixtures/blocks/*.serialized.html' ) as $path ) { $filename = basename( $path ); $block = file_get_contents( $path ); $data[] = array( $block, $filename ); } return $data; } }