[wp-trac] [WordPress Trac] #55274: Special chars in attachment filename breaks srcset

WordPress Trac noreply at wordpress.org
Mon Feb 28 11:53:10 UTC 2022


#55274: Special chars in attachment filename breaks srcset
--------------------------+------------------------
 Reporter:  dravnic       |       Owner:  audrasjb
     Type:  defect (bug)  |      Status:  reviewing
 Priority:  normal        |   Milestone:  6.0
Component:  Media         |     Version:
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------

Comment (by dravnic):

 I've tried using {{{esc_url()}}} like in
 https://core.trac.wordpress.org/attachment/ticket/36549/36549.2.diff but
 it didn't help.

 The image filename that I used to test this is {{{smeće-1024x614.png}}}
 the special char in this filename is {{{ć}}} - a Croatian letter. In the
 src attribute path is properly encoded {{{sme%C4%87e-1024x614.png}}}}

 With current code and with {{{esc_url()}}} the image was encoded in srcset
 as {{{smeće-1024x614.png}}} which is an invalid url.

 When patched with
 https://core.trac.wordpress.org/attachment/ticket/55274/55274.3.diff it
 was encoded as {{{sme%C4%87e-1024x614.png}}} which is ok.

 So {{{rawurlencode()}}} seems a better option, but it cannot be used after
 filter because then it would encode entire url not only filename. Maybe to
 extract filename from the full path and then encode it and append back on
 its path. Although directory name can as well contain special chars. To
 cover these cases it work require a bit more logic.

 It would be great if we could encode before the filter and then leave it
 to filter to handle its urls properly.

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


More information about the wp-trac mailing list