[wp-trac] [WordPress Trac] #39768: Incorrect image returned with attachment_url_to_postid()

WordPress Trac noreply at wordpress.org
Fri Dec 20 19:32:41 UTC 2019


#39768: Incorrect image returned with attachment_url_to_postid()
--------------------------+------------------------------
 Reporter:  ben.greeley   |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  General       |     Version:  4.7.2
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by archon810):

 I'm not sure how, but we're also running into a situation when two images
 named, say, `Home.png` and `home.png`, are uploaded days apart, and WP
 doesn't assign `-1` to one of them.

 The issue is then that `attachment_url_to_postid()` runs a query without
 checking the case, 2 rows are returned from the db, and it always picks
 the first one, which is wrong.

 A simple solution seems to be forcing the case check in this function's
 query using `BINARY` https://stackoverflow.com/a/5629121/47680.

 I'm really not sure why `-1` isn't appended, and in my test just now it
 did, but we have several examples in the db where mixed case files exist
 in the same dir.

 We've worked around it by duplicating and fixing
 attachment_url_to_postid() ourselves, but would love to see the fix in the
 core.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/39768#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list