[wp-trac] [WordPress Trac] #36549: Space in attachment filename breaks srcset

WordPress Trac noreply at wordpress.org
Wed May 18 00:40:15 UTC 2016


#36549: Space in attachment filename breaks srcset
--------------------------+------------------------------
 Reporter:  underdude     |       Owner:  joemcgill
     Type:  defect (bug)  |      Status:  reviewing
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Media         |     Version:  trunk
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by gnowland):

 Typical +1 "it could happen to anyone" post as this issue bit me too.
 Here's the fix via filter for anyone else who may have this problem, as it
 took me a non-trivial amount of time (multiple) to debug and patch. It
 would be great to see the above patch applied to cover those cases where
 image urls are malformed for whatever reason. Thanks guys.

 {{{#!php
 <?php
 function mynamespace_encode_img_src($sources){
         foreach($sources as $source => $values ){
                 $sources[$source]['url'] = str_replace( ' ', '%20',
 $values['url'] );
         }
         return $sources;
 }
 add_filter( 'wp_calculate_image_srcset', 'mynamespace_encode_img_src', 10,
 1 );
 }}}

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


More information about the wp-trac mailing list