<?php

function test_multibyte_truncation() {
	global $wpdb;

	header( "Content-Type: text/plain" );

	$comment = array(
		'comment_author' => 'ﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃ',
		'comment_content' => '',
		'comment_author_IP' => '',
		'comment_author_url' => '',
		'comment_author_email' => '',
	);

	echo "Unchanged author string (1):\n";
	var_dump( $comment['comment_author'] );

	$filtered_once = wp_filter_comment( $comment );
	echo "Filtered author string (1):\n";
	var_dump( $filtered_once['comment_author'] );

	$filtered_once['comment_author'] = $wpdb->strip_invalid_text_for_column( $wpdb->comments, 'comment_author', $filtered_once['comment_author'] );

	echo "Filtered and stripped author string (1):\n";
	var_dump( $filtered_once['comment_author'] );

	$filtered_after_stripping = wp_filter_comment( $filtered_once );

	echo "Refiltered and stripped author string (1):\n";
	var_dump( $filtered_after_stripping['comment_author'] );


	$comment['comment_author'] = 'Aﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃﾃ';

	echo "Unchanged author string (2):\n";
	var_dump( $comment['comment_author'] );

	$filtered_once = wp_filter_comment( $comment );
	echo "Filtered author string (2):\n";
	var_dump( $filtered_once['comment_author'] );

	$filtered_once['comment_author'] = $wpdb->strip_invalid_text_for_column( $wpdb->comments, 'comment_author', $filtered_once['comment_author'] );

	echo "Filtered and stripped author string (2):\n";
	var_dump( $filtered_once['comment_author'] );

	$filtered_after_stripping = wp_filter_comment( $filtered_once );

	echo "Refiltered and stripped author string (2):\n";
	var_dump( $filtered_after_stripping['comment_author'] );

	die;
}

if ( isset( $_GET['test-multibyte-truncation'] ) ) {
	add_action( 'init', 'test_multibyte_truncation', 99 );
}