Make WordPress Core

Opened 8 years ago

Last modified 5 years ago

#37103 new defect (bug)

get_comments_number_text() should not replace '%' in post title

Reported by: sergeybiryukov's profile SergeyBiryukov Owned by:
Milestone: Priority: normal
Severity: normal Version: 4.2
Component: Comments Keywords: has-patch has-unit-tests
Focuses: Cc:


Background: #13651

  1. Create a post titled "Hello % world".
  2. Add a couple of comments.
  3. comments_popup_link() will produce the following output:
    <a href="...">2 Comments <span class="screen-reader-text"> on Hello 2 world!</span>

Note "Hello 2 world!" instead of "Hello % world!", due to get_comments_number_text() treating % as a comments number.

Reproduced with 4.5.2 and Twenty Sixteen. Technically introduced in [31388].

Attachments (2)

37103.diff (634 bytes) - added by andizer 8 years ago.
37103.patch (2.8 KB) - added by keesiemeijer 8 years ago.
Replace % in post titles and add unit tests

Download all attachments as: .zip

Change History (11)

#2 @rachelbaker
8 years ago

  • Keywords needs-patch added
  • Milestone changed from Awaiting Review to Future Release

#3 @andizer
8 years ago

I have a fix for this issue, but I am not sure if it's the right one. Please give me some feedback on my fix.

8 years ago

#4 @andizer
8 years ago

  • Keywords has-patch added; needs-patch removed

#5 @andizer
8 years ago

  • Keywords needs-testing added

#6 @johnbillion
8 years ago

  • Keywords needs-patch needs-unit-tests added; has-patch needs-testing removed

Thanks for the patch, @andizer, but your change means that the string % Comments would be turned into 2 instead of 2 Comments.

I think the fix is to replace any % symbols in the post title with a placeholder (such as __PERCENT__), do the comment number replacement, and then swap the placeholder back out for a %.

#7 @andizer
8 years ago

As far as I can see, the patch will fix te case where the input isn't translated.

8 years ago

Replace % in post titles and add unit tests

#8 @keesiemeijer
8 years ago

  • Keywords has-patch has-unit-tests added; needs-patch needs-unit-tests removed

#9 @keesiemeijer
8 years ago

In 37103.patch the % character is replaced by __PERCENT__ in post titles for posts with more than 1 comment. After the comment number replacement is done it's replaced back to %.

I didn't remove this unit test as it's (I think) the default behavior for get_comments_number_text(). Maybe we should remove the comment though.

Version 0, edited 8 years ago by keesiemeijer (next)
Note: See TracTickets for help on using tickets.