Make WordPress Core

Opened 9 years ago

Closed 9 years ago

#33109 closed defect (bug) (fixed)

attachment_url_to_postid() fails if url protocols don't match

Reported by: welcher's profile welcher Owned by: wonderboymusic's profile wonderboymusic
Milestone: 4.4 Priority: normal
Severity: normal Version: 4.0
Component: Media Keywords: has-patch dev-feedback early 2nd-opinion
Focuses: Cc:

Description

If attachment_url_to_postid() is passed a url with a protocol that does not match the upload directory url protocol the substr() call does not remove the appropriate part of the url and the subsquent database lookup does not retrieve the ID correctly and the method returns 0. I discovered this when working with a client site that had an http front end but an https backend.

I have attached the unit tests and fix patches separately so the issue can be seen before applying the fix which resolved the issue.

Attachments (3)

33109-unit-tests.diff (1.0 KB) - added by welcher 9 years ago.
Unit Tests
33109.diff (703 bytes) - added by welcher 9 years ago.
Patch file
33109-unit-tests.2.diff (851 bytes) - added by welcher 9 years ago.
Refreshed unit tests patch.

Download all attachments as: .zip

Change History (9)

@welcher
9 years ago

Unit Tests

@welcher
9 years ago

Patch file

#1 @welcher
9 years ago

  • Summary changed from attachment_url_to_postid() fail if url protocols don't match to attachment_url_to_postid() fails if url protocols don't match

#2 @SergeyBiryukov
9 years ago

  • Milestone changed from Awaiting Review to 4.3
  • Version changed from trunk to 4.0

#3 @obenland
9 years ago

  • Milestone changed from 4.3 to Future Release

We're a few days away from RC, let's do this in a future release.

#4 @welcher
9 years ago

  • Keywords early added

@welcher
9 years ago

Refreshed unit tests patch.

#5 @welcher
9 years ago

  • Keywords 2nd-opinion added
  • Milestone changed from Future Release to 4.4

Added a refreshed patch for the unit tests the other patch applied cleanly for me.

#6 @wonderboymusic
9 years ago

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

In 33705:

Ensure that attachment_url_to_postid() matches cross-scheme when front-end and back-end schemes are different.

Adds unit test.

Props welcher.
Fixes #33109.

Note: See TracTickets for help on using tickets.