Make WordPress Core

Opened 10 years ago

Last modified 5 days ago

#39535 new defect (bug)

Canonical redirects disallow tag named comments

Reported by: dwc Owned by:
Priority: normal Milestone: Future Release
Component: Canonical Version:
Severity: normal Keywords: has-patch has-unit-tests changes-requested
Cc: Focuses:

Description

The redirect_canonical function includes a regular expression replacement which effectively disallows tags named "comments" to have an RSS feed:

​https://github.com/WordPress/WordPress/blob/master/wp-includes/canonical.php#L285

For example:

/blog1/tag/comments/feed/

This is redirected to:

/blog1/tag/feed/

Could / should the regular expression on line 285 could pay attention to the first placeholder it matched (comments/?) or check whether the page is a tag request?

Attachments (2)

39535.diff​ (1.4 KB ) - added by asalce 10 years ago.
39535.unit-test.patch​ (1.8 KB ) - added by asalce 10 years ago.

Download all attachments as: .zip

Change History (22)

#1 @asalce
10 years ago

  • Keywords has-patch needs-testing added

@dwc I attached a patch which should work. The safest way was to check against the generated site-wide comments feed. Could you take look and let me know if that solves your issue?

#2 @asalce
10 years ago

@dd32 @markjaquith I looked a bit at the source code and this seems like it has been around for a while. Sorry to pull you in on this one, not sure who would be assigned :)

Here is the commit on Git:
​https://github.com/WordPress/WordPress/commit/ecffc4649f4cb90b43fe0b38ab0f4b18967cb3fd

I was able to reproduce the bug myself, real easy to do so. Just create a tag named "comments" and then try to load the rss feed for the tag: ​http://URL/tag/comments/feed/

Edit: tagged the canonical gods

Last edited 10 years ago by asalce (previous) (diff)

This ticket was mentioned in ​Slack in #core by asalce. ​View the logs.


10 years ago

#4 @swissspidy
10 years ago

  • Keywords needs-unit-tests added
  • Version 4.7

#5 @dwc
10 years ago

@asalce Thanks for the patch! I've confirmed it works in my setup.

#6 @asalce
10 years ago

@swissspidy I submitted the unit-test, The best way I could test this out was to test if the query vars were set correctly after a go_to("/tag/comments/feed/") the query vars should have a "feed" and "tag" should equal "comments" , I also added some other tests to make sure tests were running correctly.

@dwc perfect! :)

This ticket was mentioned in ​Slack in #core by asalce. ​View the logs.


10 years ago

This ticket was mentioned in ​Slack in #core by asalce. ​View the logs.


10 years ago

#9 follow-up: @SergeyBiryukov
10 years ago

  • Milestone Awaiting Review → 4.8

#10 in reply to: ↑ 9 @asalce
10 years ago

Replying to SergeyBiryukov:

I ran into this bug with another site, Any chance this could be moved into 4.7.x ?

#11 @javix
10 years ago

I have tested this patch successfully, it works for me.

This ticket was mentioned in ​Slack in #core by obenland. ​View the logs.


10 years ago

#13 @obenland
10 years ago

  • Milestone 4.8 → Future Release

This ticket was mentioned in ​Slack in #core by asalce. ​View the logs.


9 years ago

#15 @asalce
8 years ago

Can this one also be put up for review?
​https://make.wordpress.org/core/2019/02/20/reverting-the-bulk-ticket-closing/ @obenland @JeffPaul

#16 @JeffPaul
8 years ago

@asalce I don't think this ticket relates to the bulk ticket closing, but if you're asking about getting this milestoned then your best bet is to check with the Canonical component maintainers (see ​https://make.wordpress.org/core/components/permalinks/canonical/).

#17 @asalce
8 years ago

@JeffPaul Thanks!

@markjaquith this ticket has been in my account for a bit. I supplied a patch and unit testing awhile ago. Let me know what else is needed to get this into a release. Thanks!

  • Alberto S.

This ticket was mentioned in ​PR #8981 on ​WordPress/wordpress-develop by ​@SirLouen.


17 months ago
#18

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

This patch is not working. Unit Tests not passing. Needs more work.

Trac ticket: https://core.trac.wordpress.org/ticket/39535

#19 @SirLouen
17 months ago

  • Keywords changes-requested added; needs-testing removed

Patch has been refreshed, but still unit tests are not passing. Needs more work.

cc @asalce

This ticket was mentioned in ​PR #15982 on ​WordPress/wordpress-develop by ​@irozum.


5 days ago
#20

redirect_canonical() strips an optional comments/ segment before any feed ending, so /tag/comments/feed/ is redirected to /tag/feed/ (and /category/comments/feed/ to /category/feed/). A term with the slug comments could therefore never serve its feed.

Only a comments feed has a comments/ segment to strip, and those always set withcomments. The add-back step already only re-adds comments/ when withcomments is set, so this makes the strip step match it: the comments/ segment is only stripped when withcomments is set.

The site-wide comments feed (/comments/feed/, ?feed=comments-rss2) and per-post comment feeds are unaffected and covered by the existing canonical tests. New tests cover tag and category feeds for a term named comments.

Earlier work on this ticket, including the 2017 patch and the refresh in #8981, was a starting point for the investigation. #8981 notes its tests did not pass, so this takes a different approach that does not depend on the host or permalink structure.

A related issue is not addressed here: a term named feed, rss or atom (e.g. /tag/feed/feed/) is still over-stripped by the repeated stripping in the while loop. That could be a follow-up.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Sonnet 5.5
Used for: Implementation, tests, and PR description.

---
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See ​GitHub Pull Requests for Code Review in the Core Handbook for more details.

🤖 Generated with ​Claude Code

Note: See TracTickets for help on using tickets.