Make WordPress Core

Opened 7 weeks ago

Last modified 6 weeks ago

#64552 new defect (bug)

wp_trim_words fails with certain charsets in the Excerpt

Reported by: sirlouen's profile SirLouen Owned by:
Milestone: Future Release Priority: normal
Severity: normal Version: 3.0
Component: Formatting Keywords: needs-patch has-test-info
Focuses: Cc:

Description (last modified by SirLouen)

Bug Report

Following the GB74925 we have noticed that the excerpts were not being adapted accordingly in the Editor. It was also noticed that the current regex trim was not applying for certain more edge character types of cases like

Environment

  • WordPress: 7.0-alpha-61215-src
  • PHP: 8.2.29
  • Server: nginx/1.29.4
  • Database: mysqli (Server: 8.4.7 / Client: mysqlnd 8.2.29)
  • Browser: Chrome 144.0.0.0
  • OS: Windows 10/11
  • Theme: Twenty Twenty-Three 1.6
  • MU Plugins: None activated
  • Plugins:
    • Gutenberg 22.4.1

Testing Instructions

  1. Ideally use the 2023 theme
  2. Create a new post and add the following excerpt:
Fabio vel iudice vincam, sunt	in	culpa	qui officia.
Inmensae subtilitatis, obscuris et malesuada fames.
Ambitioni dedisse scripsisse iudicaretur.
Nec dubitamus multa iter quae et nos invenerat.
Petierunt uti sibi concilium totius Galliae in diem certam indicere.
  1. Go to Appearance > Editor
  2. Click on the canvas
  3. Select the excerpt of the newly created Post
  4. Adjust the Excerpt Max Number of Words (you need Gutenberg trunk to test this; if you don't use trunk, it will not work either in the Editor).
  5. Set, for example, 30 words, and Save
  6. Go to the front end.
  7. 🐞 The number of words is not the same as in the editor.

Expected Behaviour

  • The number of words of the excerpt should be the same in the Editor and in the front end.

Additional Information

Apparently, it appears that the wp_trim_words is not trimming all types of spacing characters accordingly; hence, the word count is inconsistent. @wildworks proposed that the /[\n\r\t ]+/ must be fixed for this purpose.

It appears that this was first introduced in [13942]/#10376

Change History (2)

#1 @SirLouen
7 weeks ago

  • Description modified (diff)

#2 @SirLouen
6 weeks ago

  • Milestone changed from 7.0 to Future Release

Pushing back to Future Release, as we don't really have a patch for it yet.

Note: See TracTickets for help on using tickets.