WordPress.org

Make WordPress Core

Opened 4 years ago

Closed 4 years ago

#11244 closed defect (bug) (fixed)

wp_widget_rss_output with show_summaryshows two ellipses

Reported by: aaroncampbell Owned by: westi
Milestone: 3.0 Priority: low
Severity: trivial Version: 2.9
Component: Widgets Keywords: has-patch
Focuses: Cc:

Description

You should be able to see this by looking at the WordPress Development Blog feed on the dashboard. One is actually three periods, and one is …

It looks like the problem is that feeds (including those created by WordPress) often have a description that is shorter than 360 characters and already ends in [...], which means that the string is not shortened at all, but is treated as though it was. The … is added in wp-includes/default-widgets.php on line 804:

$desc = wp_html_excerpt( $desc, 360 ) . ' […]';

Attachments (5)

11244.patch (601 bytes) - added by tosak 4 years ago.
11244-double-hellip.diff (669 bytes) - added by nacin 4 years ago.
11244-double-hellip.2.diff (832 bytes) - added by nacin 4 years ago.
11244-double-hellip.3.diff (833 bytes) - added by nacin 4 years ago.
Noticed that patch 2 was missing a space before the […]. This one adds it.
11244.4.diff (1.0 KB) - added by nacin 4 years ago.
Using regular expressions

Download all attachments as: .zip

Change History (18)

comment:1 ShaneF4 years ago

  • Component changed from General to Administration
  • Owner set to ShaneF
  • Status changed from new to accepted

Going to work on a patch right now for it.

tosak4 years ago

comment:2 tosak4 years ago

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

Patch only adds […] if strlen is over 360.

comment:3 nacin4 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Patches are only "fixed" once they are committed to the codebase.

nacin4 years ago

comment:4 nacin4 years ago

  • Component changed from Administration to Widgets
  • Keywords has-patch added
  • Owner changed from ShaneF to nacin
  • Priority changed from normal to low
  • Severity changed from normal to trivial
  • Status changed from reopened to accepted

Patch attached to remove double ellipses appearing at the end of a description.

comment:5 westi4 years ago

  • Milestone changed from 2.9 to 3.0
  • Owner changed from nacin to westi

Not sure this is the best solution also as it is not a regression I am going to move it to 3.0

comment:6 nacin4 years ago

Ah, thanks, I meant to punt this.

Not sure if this is the best solution either, but the problem is that you can't simply remove any [...] or […] that appear in a description. They're sometimes used to denote the removal of information in a quote, for example, so they might not always be deliberately at the end of a description. The patch avoids using regular expressions or multiple substr to check if the ellipses appear at the end of the description.

Then again, a simpler way might just be to check mb_strlen for < 360.

nacin4 years ago

nacin4 years ago

Noticed that patch 2 was missing a space before the [&hellip;]. This one adds it.

comment:7 Denis-de-Bernardy4 years ago

  • Keywords needs-patch added; has-patch removed

mb_strlen() is not available on all servers, as can be seen based on the couple of forum support tickets related to Magpie failing to convert UTF-8 into UTF-8

comment:8 Denis-de-Bernardy4 years ago

an alternative approach could be to try to remove ellipses using preg_replace()

comment:9 follow-up: nacin4 years ago

  • Keywords dev-feedback added

We use a handful of mb_* functions, though perhaps that should be addressed. In this case, I used mb_strlen() since wp_html_excerpt() uses mb_substr(). So really, the latest patch works fine until we rid core of mb_* functions.

I had wanted to avoid preg_replace() but yes, that would do it as well.

comment:10 in reply to: ↑ 9 nacin4 years ago

  • Keywords dev-feedback removed

Replying to nacin:

We use a handful of mb_* functions, though perhaps that should be addressed. In this case, I used mb_strlen() since wp_html_excerpt() uses mb_substr(). So really, the latest patch works fine until we rid core of mb_* functions.

I stand quite corrected. Every time an mb_* function is used, its existence is first checked, except for mb_substr, which has a fallback in compat.php.

comment:11 nacin4 years ago

  • Keywords has-patch added; needs-patch removed

New patch, using preg_match.

Checks for existence of [...] or [&hellip;] at the end of an excerpt. If neither is found, it adds [&hellip;]. If [...] is found, it converts it to [&hellip;].

nacin4 years ago

Using regular expressions

comment:12 hakre4 years ago

sometimes a substr does work as well:

$desc = preg_replace( '/\[...\]$/D', ' [&hellip;]', $desc );

might be faster then a preg_replace. even with an if and a str_replace().

comment:13 nacin4 years ago

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

[13328] Don't show two ellipses in wp_widget_rss_output(). Fixes #11244 props miqrogroove

Note: See TracTickets for help on using tickets.