Skip to:
Content

bbPress.org

Opened 7 years ago

Closed 7 years ago

#3170 closed defect (bug) (fixed)

bbp_get_topic_excerpt wrong result of multibyte string

Reported by: it4life's profile it4life Owned by: johnjamesjacoby's profile johnjamesjacoby
Milestone: 2.6 Priority: normal
Severity: normal Version: 2.5.14
Component: General Keywords: needs-patch good-first-bug
Cc:

Description

The function bbp_get_topic_excerpt is currently using substr which does not support multibyte string. So the excerpt may have invalid character.
E.g. Topic content:

Khi đăng ký thành viên, một Email kích hoạt và đặt mật khẩu sẽ được gửi đến địa chỉ Mail của các bạn.

Result of bbp_get_topic_excerpt:

Khi đăng ký thành viên, một Email kích hoạt và đặt mật khẩu sẽ được gửi �…

Suggest edit: using mb_substr

<?php
if ( function_exists( 'mb_substr' ) ) {
    $excerpt  = mb_substr( $excerpt, 0, $length - 1 );
} else {
    $excerpt  = substr( $excerpt, 0, $length - 1 );
}

Thanks!

Change History (3)

#1 @johnjamesjacoby
7 years ago

  • Keywords needs-patch good-first-bug added
  • Milestone changed from Awaiting Review to 2.6
  • Owner set to johnjamesjacoby

This should use the multibyte equivalent.

#2 @johnjamesjacoby
7 years ago

mb_substr() is provided via compat.php so we can use it directly internally.

I'm going to use it in 2 additional places, where values *could* contain multibyte characters.

#3 @johnjamesjacoby
7 years ago

  • Resolution set to fixed
  • Status changed from new to closed

In 6722:

Formatting: Use mb_substr() where appropriate.

This change ensures that strings which are known to contain or allow for multibyte characters are allowed to do so (in excerpts and a few server globals.)

Fixes #3170. Props it4life.

Note: See TracTickets for help on using tickets.