WordPress.org

Make WordPress Core

Opened 4 years ago

Last modified 3 years ago

#12634 new defect (bug)

Media Library & Permalink Overlap

Reported by: tmoorewp Owned by: ryan
Milestone: Future Release Priority: normal
Severity: normal Version: 2.9.1
Component: Permalinks Keywords: has-patch needs-testing
Focuses: Cc:

Description

The problem is: upload a media item and give it a name, such as 'test'. Create a new page titled 'test' with a permalink that reads http://www.example.org/test/.

The permalink, instead of going to the page, goes to the media item.

For most purposes, I would imagine this behavior should be reversed.

-Tim-

Attachments (1)

12634.diff (955 bytes) - added by solarissmoke 3 years ago.
Check for attachments sharing the same parent as the current page when finding a unique slug

Download all attachments as: .zip

Change History (18)

comment:1 tmoorewp4 years ago

  • Cc tim.moore@… added

comment:2 nacin4 years ago

  • Component changed from Media to Rewrite Rules
  • Milestone changed from 2.9.3 to 3.0
  • Owner set to ryan

comment:3 dd324 years ago

How did you change the media name to 'test'?

The post_name field which this is based off is supposed to be unique, The only way i could force what you describe to happpen, was to change the post_name field in the database so that they conflicted.

comment:4 dd324 years ago

  • Keywords reporter-feedback added

comment:5 tmoorewp4 years ago

In the tests I did, the media item was uploaded first and then the page/post was created. I first ran across this problem in a 2.9.1.1 WPMU installation I run at a university, but have also seen it happen on a standalone 2.9.2 WP install.

Also, I haven't modified anything in the database that would effect this. All the tests I ran were strictly uploading media through the Dashboard and creating posts/pages in the Dashboard. No database modification was needed, on my part, to produce this error.

comment:6 dremeda4 years ago

  • Cc dre@… added

I tried recreating this by first uploading a media item, then created a page and do not see the same issue. The page is properly created as expected.

So when you say give it a name like "test" are you speaking to changing the title of the uploaded media item?

comment:7 tmoorewp4 years ago

Dremeda: Yes, it happens when you change the title of the media item to the same name as a page has.

So:

  1. Media Item is uploaded, Title field == 'test'.
  2. A page is created after the media item is created. Page is named 'test' and permalink is example.org/test.
  3. The URL example.org/text goes to the Media Item created in step 1, rather than to the page created in step 2.

I've been able to easily recreate this behavior on my test installs, but I'll go back through and check again.

Thanks!

Tim

comment:8 dremeda4 years ago

Thanks Tim,

I tried recreating this multiple times with pages and posts the same way you outlined and could not recreate the error.

I was working on localhost, I will try and recreate on a dev server today.

comment:9 nacin4 years ago

  • Milestone changed from 3.0 to Unassigned

comment:10 nacin4 years ago

Similar symptoms? #10988

comment:11 dremeda4 years ago

Similar symptoms but not sure its the same thing.

On this ticket, I tried on a dev server after I tested on localhost and could not recreate in either case.

comment:12 madtownlems4 years ago

  • Cc madtownlems added

I can easily replicate this error on both 2.9.1 and 3.0.1. Here's my (overly detailed) write up:

When you upload a media item, it creates a permalink for the piece of media. (you can view the permalink by hovering over View for the media link in the media library)

  • If you upload it from the left menu “Media – Add New” the permalink will look like: blah.com/?attachment_id=57
  • If you upload while creating/editing a page, the permalink will use the structure: blah.com/<path-to-page>/image-title

If the permalink is already taken, say as by an existing page, it will make it unique by appending something like “-2” to the end.

When you create a new page, it generates a permalink in the form of <path-to-parent-page>/page-title

HOWEVER – and herein lies the problem – it does NOT check if the permalink is taken by an existing media item (but it DOES compare it against existing page permalinks).

So, in order to experience the problem, I believe the following all need to be true:
1) You add the media via the Upload/Insert link while creating the page
2) You upload the images BEFORE you create the pages
3) The pages have the same title as the image title

Steps to Recreate Example:
Create page /tool
Create page /tool/hammer
Edit /tool. Add images called hammer.jpg and saw.jpg, link hammer.jpg to /tool/hammer and saw.jpg to /tool/saw
Create page /tool/saw

Expected behavior:
/tool/hammer should take you to the page itself
/tool/saw should display the saw.jpg instead of the page
Desired behavior:
/tool/saw should display the saw page.

comment:13 mrmist4 years ago

  • Keywords reporter-feedback removed
  • Version set to 2.9.1

I can confirm that this is reproducable in 3.0.1.

(Also setting the version to the earliest version I saw mentioned above.)

There doesn't appear to be checking of permalinks against media items when creating a page. The Page equipment / lawnmower will show the media item for "lawnmower".

comment:14 nacin3 years ago

  • Milestone changed from Awaiting Review to Future Release

comment:15 nacin3 years ago

  • Keywords needs-patch added

solarissmoke3 years ago

Check for attachments sharing the same parent as the current page when finding a unique slug

comment:16 solarissmoke3 years ago

  • Component changed from Rewrite Rules to Permalinks
  • Keywords has-patch needs-testing added; needs-patch removed

This fixes it for me - we just need to be checking for attachments that share the same parent as the page being edited.

comment:17 garyc403 years ago

Similar to #15655, although in #15655, the permalink conflict is between attachment and child pages. There's a patch there as well.

Note: See TracTickets for help on using tickets.