WordPress.org

Make WordPress Core

Opened 3 years ago

Closed 9 months ago

Last modified 9 months ago

#15665 closed defect (bug) (fixed)

Page name won't work if the parent page has an attachment with the same name

Reported by: designsimply Owned by: nacin
Priority: high Milestone: 3.5
Component: Permalinks Version: 3.1
Severity: normal Keywords: has-patch needs-testing early
Cc: westi, ipstenu@…

Description

It's possible to create a page name that has the same name as an attachment page with the same parent. If you do that, the attachment page takes precedent and it's not possible to display the page with the matching name.

To reproduce:

  1. Create a page, attach some images to it, save and publish
  2. Create a child page with the same name as one of images attached to the parent page

---> Result: a page name and an attachment page name that are the same and it's not possible to view the page at http://example.com/parent_page_name/page_name/

Tested with r16708

Making the attachment post type hierarchical fixes it this my tests. Is there any reason attachment post types should not be hierarchical?

Attachments (5)

post.diff (517 bytes) - added by designsimply 3 years ago.
garyc40.15665.diff (1.0 KB) - added by garyc40 2 years ago.
fixed get_page_by_path()
15665.patch (1013 bytes) - added by SergeyBiryukov 12 months ago.
15665-unit.patch (2.4 KB) - added by devesine 12 months ago.
Here's a unit test which tests this bug. Comments gratefully accepted - particularly as this is the first WP test I've written.
15665-unit-2.patch (2.5 KB) - added by devesine 12 months ago.

Download all attachments as: .zip

Change History (30)

designsimply3 years ago

comment:1 nacin3 years ago

This is definitely duplicating another ticket somewhere. But I think this is the first time I've seen it well-explained and with a patch. :)

comment:2 scribu3 years ago

  • Keywords needs-patch added; has-patch needs-testing removed
  • Milestone changed from Awaiting Review to Future Release

Making the attachment post type hierarchical fixes it this my tests. Is there any reason attachment post types should not be hierarchical?

Yes, attachments are not hierarchical because it doesn't make sense to link an attachment to another attachment.

We should find a better way to fix this.

comment:3 follow-up: westi3 years ago

I suspect the real fix here is to find out why we match attachment slugs when looking up root level pages

comment:4 westi3 years ago

  • Cc westi added

comment:5 designsimply3 years ago

Found two additional cases where it's possible to add pages that conflict with auto-generated pages:

  • author/EXISTING_BLOG_USER
  • category/EXISTING_CATEGORY

This is in addition to the case originally reported where it's possible to add a page that conflicts with existing attachment pages names for the same parent page:

  • PARENT_PAGE/ATTACHMENT_PAGE

garyc402 years ago

fixed get_page_by_path()

comment:6 garyc402 years ago

  • Keywords has-patch needs-testing 3.2-early added; needs-patch removed

comment:7 garyc402 years ago

Can't reproduce your problem with author and category though. More detailed steps?

comment:8 SergeyBiryukov22 months ago

  • Keywords needs-refresh added

Closed #16438 as a duplicate.

comment:9 Ipstenu22 months ago

  • Cc ipstenu@… added

comment:10 in reply to: ↑ 3 ; follow-up: duck_18 months ago

#19683 was closed as a duplicate, apparently root level pages were not susceptible to collisions prior to 3.3. This is might due to changes in get_page_by_path(), see #16687.

Replying to westi:

I suspect the real fix here is to find out why we match attachment slugs when looking up root level pages

get_page_by_path() queries for attachment as well as the specified post type.

Related #17170.

comment:11 in reply to: ↑ 10 duck_18 months ago

Replying to duck_:

apparently root level pages were not susceptible to collisions prior to 3.3.

Sorry for repeating that without double checking. It's wrong.

comment:12 SergeyBiryukov14 months ago

Closed #20612 as a duplicate.

comment:13 Viper007Bond13 months ago

  • Component changed from General to Permalinks
  • Priority changed from normal to high

This is super annoying. We should resolve this.

comment:14 SergeyBiryukov12 months ago

Closed #21008 as a duplicate.

SergeyBiryukov12 months ago

comment:16 SergeyBiryukov12 months ago

  • Keywords early added; 3.2-early needs-refresh removed
  • Milestone changed from Future Release to 3.5

15665.patch compares found post type with the requested one before breaking the loop, to see if we can find an item that meets all other requirements and also has the same post type.

comment:17 nacin12 months ago

  • Keywords needs-unit-tests added

+1 for 3.5.

devesine12 months ago

Here's a unit test which tests this bug. Comments gratefully accepted - particularly as this is the first WP test I've written.

comment:18 devesine12 months ago

15665-unit.patch executes the reproduction steps described in the bug; currently fails, passes with patch applied.

comment:19 trepmal12 months ago

Just came across a little issue which I believe is related to this.

If I have a page "Rooms," for example, with child page "Amenities" as well as a CPT with 'rooms' as the rewrite slug (below), the child page /rooms/amenties/ will 404 as 'amenties' is expected to be part of the CPT

register_post_type('room', array(
	//...
	'rewrite' => array('slug' => 'rooms')
	//...
));

If unrelated, let me know, I'll check again for an existing ticket or open a new one.

comment:20 follow-up: nacin12 months ago

I think we can simply call wp_insert_attachment() rather than actually upload a file for 15665-unit.patch.

trepmal, that does not appear related.

devesine12 months ago

comment:21 in reply to: ↑ 20 devesine12 months ago

Replying to nacin:

simply call wp_insert_attachment()

Looks like that works fine; updated in 15665-unit-2.patch.

comment:22 SergeyBiryukov11 months ago

Closed #21216 as a duplicate.

comment:23 SergeyBiryukov11 months ago

Closed #21501 as a duplicate.

comment:24 nacin9 months ago

  • Owner set to nacin
  • Resolution set to fixed
  • Status changed from new to closed

In [21845]:

In get_page_by_path(), attempt to return an item that has the same post type before returning an attachment with the same name. props SergeyBiryukov. tests in [UT1021]. fixes #15665.

comment:25 nacin9 months ago

  • Keywords needs-unit-tests removed
Note: See TracTickets for help on using tickets.