Make WordPress Core

Ticket #36393: test-multibyte-truncation.php

File test-multibyte-truncation.php, 2.2 KB (added by cfinke, 10 years ago)

A POC plugin for observing how a commenter name can be truncated.

Line 
1<?php
2
3function test_multibyte_truncation() {
4        global $wpdb;
5
6        header( "Content-Type: text/plain" );
7
8        $comment = array(
9                'comment_author' => 'テテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテ',
10                'comment_content' => '',
11                'comment_author_IP' => '',
12                'comment_author_url' => '',
13                'comment_author_email' => '',
14        );
15
16        echo "Unchanged author string (1):\n";
17        var_dump( $comment['comment_author'] );
18
19        $filtered_once = wp_filter_comment( $comment );
20        echo "Filtered author string (1):\n";
21        var_dump( $filtered_once['comment_author'] );
22
23        $filtered_once['comment_author'] = $wpdb->strip_invalid_text_for_column( $wpdb->comments, 'comment_author', $filtered_once['comment_author'] );
24
25        echo "Filtered and stripped author string (1):\n";
26        var_dump( $filtered_once['comment_author'] );
27
28        $filtered_after_stripping = wp_filter_comment( $filtered_once );
29
30        echo "Refiltered and stripped author string (1):\n";
31        var_dump( $filtered_after_stripping['comment_author'] );
32
33
34        $comment['comment_author'] = 'Aテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテテ';
35
36        echo "Unchanged author string (2):\n";
37        var_dump( $comment['comment_author'] );
38
39        $filtered_once = wp_filter_comment( $comment );
40        echo "Filtered author string (2):\n";
41        var_dump( $filtered_once['comment_author'] );
42
43        $filtered_once['comment_author'] = $wpdb->strip_invalid_text_for_column( $wpdb->comments, 'comment_author', $filtered_once['comment_author'] );
44
45        echo "Filtered and stripped author string (2):\n";
46        var_dump( $filtered_once['comment_author'] );
47
48        $filtered_after_stripping = wp_filter_comment( $filtered_once );
49
50        echo "Refiltered and stripped author string (2):\n";
51        var_dump( $filtered_after_stripping['comment_author'] );
52
53        die;
54}
55
56if ( isset( $_GET['test-multibyte-truncation'] ) ) {
57        add_action( 'init', 'test_multibyte_truncation', 99 );
58}