Make WordPress Core

Opened 13 years ago

Closed 9 years ago

#19918 closed defect (bug) (fixed)

Attachments are viewable from any permalink that matches their slug

Reported by: prorock's profile prorock Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.4 Priority: normal
Severity: normal Version: 3.2
Component: Permalinks Keywords: has-patch has-unit-tests
Focuses: Cc:

Description

I see one problem in WordPress, for example if you upload an images with name comments.png, all your url contain hide url like: /comments

example:
original post: yourdomain.com/myarticle
if you have in media gallery file with name comments.png url will be: yourdomain.com/myarticle/comments
or
yourdomain.com/myarticle2/comments
or
yourdomain.com/myarticle3/comments

and all this url's contain the same comment box.

my users report this problem, because if i share in twitter or g+ one link, many users redirect not to the post but to url with /comments in the end.

Adrian,

designmodo.com

Attachments (3)

19918.diff (778 bytes) - added by solarissmoke 13 years ago.
19918-circular-fragment.diff (1.3 KB) - added by tellyworth 9 years ago.
Fixes a potential circular redirect issue.
19918.2.diff (1.3 KB) - added by wonderboymusic 9 years ago.

Download all attachments as: .zip

Change History (25)

#1 @thee17
13 years ago

This would likely also effect images named page, feed, or trackback as well.

#2 @SergeyBiryukov
13 years ago

Not sure what the problem is. My steps:

  1. Switched permalink structure to /%postname%/.
  2. Created and published a new post: /test8/
  3. On Edit Post screen, uploaded comments.jpg image.
  4. URL of the post is still the same (/test8/) and opens the post without a redirect.
  5. URL of the uploaded image is /test8/comments/ and opens the image.

#3 @prorock
13 years ago

Sergey, try to create posts like /test9 and /test10 without upload any images and type in browser /test9/comments/ /test9/comments/ will appear the same image that in case of /test8/comments/

#4 @SergeyBiryukov
13 years ago

Ah, I see. Confirmed.

#5 @prorock
13 years ago

Good, waiting others for confirmation.

#6 @solarissmoke
13 years ago

  • Component changed from Comments to Permalinks
  • Summary changed from File name convert to URL to Attachments are viewable from any permalink that matches their slug
  • Version changed from 3.3.1 to 3.2

This seems to be a wider issue than what was originally reported. Basically, you can view an attachment by appending it's slug to the link for any post! To reproduce:

  • Use pretty permalinks (the exact structure doesn't matter)
  • Add an attachment to a post (e.g., with attachment URL /2012/01/30/my-post/my-attachment/)
  • Now you can view that attachment by appending the attachment slug to any other post. For example /2012/01/01/hello-world/my-attachment/ or /2011/11/01/another-random-post/my-attachment/.

The name of the attachment doesn't matter.

I can reproduce this in WP 3.2 (and 3.3, trunk). Don't have an earlier version running at the moment.

#7 @prorock
13 years ago

  • Version changed from 3.2 to 3.3.1

In 3.3.1 is the same problem, so don't change version :)

Thanks

#8 @solarissmoke
13 years ago

  • Version changed from 3.3.1 to 3.2

The version field is used to identify the earliest version at which the bug exists. Because it says 3.2 doesn't mean it doesn't exist in 3.3.

#9 @nacin
13 years ago

Sounds like something that should probably be handled by canonical.

@solarissmoke
13 years ago

#10 @solarissmoke
13 years ago

  • Keywords has-patch dev-feedback added

Here's a patch for starters. It fixes the issue for me, but I'm not too familiar with canonical so there is probably a better/more correct way to do it.

#11 @chriscct7
10 years ago

  • Severity changed from major to normal

Patch still looks good to go, but the severity of this issue isn't "major", as it doesn't really break anything. Downgrading to normal.

#12 @wonderboymusic
9 years ago

  • Keywords dev-feedback removed
  • Milestone changed from Awaiting Review to 4.4

#13 @wonderboymusic
9 years ago

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

In 34272:

Canonical: redirect URLs that match an attachment masked on the wrong URL to the attachment link for the matched attachment.

Props solarissmoke.
Fixes #19918.

#14 @swissspidy
9 years ago

  • Keywords needs-patch added; has-patch removed
  • Resolution fixed deleted
  • Status changed from closed to reopened

[34272] broke attachment endpoints

To reproduce:

  1. Add a rewrite endpoint, e.g. by using add_rewrite_endpoint( 'embed', EP_ALL ); or just add_rewrite_endpoint( 'embed', EP_ATTACHMENT );
  2. Upload an attachment to a post.
  3. Visit the attachment URL with that endpoint, e.g. http://example.org/my-awesome-post/sample-attachment/embed/.
  4. redirect_canonical redirects you to http://example.org/my-awesome-post/sample-attachment/

#15 @wonderboymusic
9 years ago

  • Owner changed from Adrian (designmodo.com) to wonderboymusic
  • Status changed from reopened to assigned

#16 @wonderboymusic
9 years ago

  • Resolution set to fixed
  • Status changed from assigned to closed

In 34643:

Canonical: after [34272], don't redirect rewrite endpoints on attachment URLs when pretty permalinks are enabled.

Fixes #19918.

#17 follow-up: @tellyworth
9 years ago

These two recent commits triggered a circular redirect in some themes on wp.com. Those themes filter attachment_link to add a fragment #main, and that interacts with the new code to redirect back to the same url.

For an example, see suburbia_enhanced_image_navigation in https://wpcom-themes.svn.automattic.com/suburbia/functions.php.

I checked with our theme team, and they think it's reasonable behaviour for a theme to do that. It's also likely that other, non-Automattic themes do something similar.

I'm not really sure what the solution is, or even if there could be a third factor interacting, but I did confirm that reverting those two commits stops the circular redirect from happening.

@tellyworth
9 years ago

Fixes a potential circular redirect issue.

#18 in reply to: ↑ 17 @tellyworth
9 years ago

  • Resolution fixed deleted
  • Status changed from closed to reopened

Replying to tellyworth:

These two recent commits triggered a circular redirect in some themes on wp.com. Those themes filter attachment_link to add a fragment #main, and that interacts with the new code to redirect back to the same url.

I'm reasonably convinced that this is a general problem in redirect_canonical(). If any of the functions used to generate a canonical URL (such as get_permalink()) are filtered to add a #fragment, this causes the circular redirect detection logic to fail.

attachment:19918-circular-fragment.diff prevents this from happening. It fixes the attachment issue, and shouldn't prevent redirecting to a URL that contains a fragment, which is probably a valid use case.

#19 @wonderboymusic
9 years ago

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

19918.2.diff fixes the patch, which had the wrong var in it, $redirect_url, which was blowing up unit tests.

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


9 years ago

#21 @boonebgorges
9 years ago

@wonderboymusic New function could use a @since annotation, but otherwise +1 from me on 19918.2.diff

#22 @wonderboymusic
9 years ago

  • Resolution set to fixed
  • Status changed from reopened to closed

In 35770:

Canonical: introduce strip_fragment_from_url() and use when comparing URLs in redirect_canonical().

Props tellyworth.
Fixes #19918.

Note: See TracTickets for help on using tickets.