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 | Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 4.2 |
Component: | Comments | Keywords: | has-patch has-unit-tests |
Focuses: | Cc: |
Description
Background: #13651
- Create a post titled "Hello % world".
- Add a couple of comments.
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)
Change History (11)
#2
@
8 years ago
- Keywords needs-patch added
- Milestone changed from Awaiting Review to Future Release
#3
@
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.
#6
@
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 %
.
#9
@
8 years ago
In 37103.patch the %
character is replaced by __PERCENT__
in the post title 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 (I think) it's the default behavior for get_comments_number_text()
. Maybe we should remove the comment though.
https://github.com/WordPress/WordPress/blob/master/wp-includes/comment-template.php#L875