Make WordPress Core

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#9055 closed defect (bug) (fixed)

mb_strcut in wp_html_excerpt seems to count bytes (not characters). Use mb_substr instead?

Reported by: demetris's profile demetris Owned by: nbachiyski's profile nbachiyski
Milestone: 2.8 Priority: normal
Severity: normal Version: 2.8
Component: I18N Keywords: has-patch tested needs-testing
Focuses: Cc:

Description

The result is that strings with multibyte characters are cut too short.

An instance of this can be seen on edit-comments.php. I have a post with this title:

αβγδεζηθικλμνξοπρστυφχψω ΑΒΓΔΕΖΗΘΙΚΛΜΝΞΟΠΡΣΤΥΦΧΨΩ

... which is 49 characters long (the 24 letters of the Greek alphabet + 1 space + the 24 letters in capital form), that is, just below the cut-off limit (50). But WP cuts the string after the 25th character, displaying:

Edit Comments on “αβγδεζηθικλμνξοπρστυφχψω ”

Replacing mb_strcut with mb_substr in wp_html_excerpt seems to fix this. I tried with Japanese and with Greek on WP 2.7 branch and on WP trunk and everything SEEMS to be OK.

Is there a reason mb_substr was not used there? Maybe some issue that has been resolved in the meantime?

Please note that I’m not a coder and that much of this stuff goes over my head. :-)

Attachments (1)

r10506-wphtmlexcerpt-mbstrcut-mbsubstr.diff (489 bytes) - added by demetris 16 years ago.
Tentatively replaces mb_strcut with mb_substr in wp_html_excerpt

Download all attachments as: .zip

Change History (7)

@demetris
16 years ago

Tentatively replaces mb_strcut with mb_substr in wp_html_excerpt

#1 @ryan
16 years ago

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

(In [10702]) Use mb_substr instead of mb_strcut in wp_html_excerpt. Props demetris. fixes #9055

#2 @nbachiyski
16 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

We have a pure php implementation of mb_strcut and if we use mb_substr(), we'll need it implemented too for installs, without the mbstring extension.

I now remembered, that in the beginning we used mb_strcut(), because we needed to limit database fields, which are counted in bytes. However, now we are using it only in wp_html_excerpt in which case mb_substr() really makes more sense.

#3 @ryan
16 years ago

Add mb_substr() to compat.php and have it use _mb_strcut()?

#4 @nbachiyski
16 years ago

It turns out that _mb_strcut()} works exactly like mb_substr and not as mb_strcut. We just need to rename _mb_strcut to _mb_substr and make the new compat function use it.

#5 @ryan
16 years ago

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

(In [10707]) Add compat for mb_substr rather than mb_strcut. fixes #9055

#6 @demetris
16 years ago

Thanks, ryan and nbachiyski, for looking into this.

Note: See TracTickets for help on using tickets.