[wp-trac] Re: [WordPress Trac] #9416: Better file name sanitization for wp_unique_filename

WordPress Trac wp-trac at lists.automattic.com
Tue Apr 21 17:06:26 GMT 2009


#9416: Better file name sanitization for wp_unique_filename
-------------------------+--------------------------------------------------
 Reporter:  sivel        |       Owner:  sivel      
     Type:  enhancement  |      Status:  assigned   
 Priority:  normal       |   Milestone:  2.8        
Component:  Upload       |     Version:  2.7.1      
 Severity:  normal       |    Keywords:  needs-patch
-------------------------+--------------------------------------------------

Comment(by Denis-de-Bernardy):

 isn't there an issue with this regex?

 {{{
 $filename = 'foo - bar';
 $filename = preg_replace('(\s+|-+)', '-', $filename); // error, foo---bar
 if it had delimiters
 }}}

 potential replacements:

 {{{
 $filename = preg_replace('/[\s\-]+/', '-', $filename);
 $filename = preg_replace('/(?:\s|-)+/', '-', $filename);
 }}}

 also, wouldn't it be more desirable to turn chars such as punctation and
 dashes into dashes, rather than eliminating them outright?

 lastly, there are potential issues here if the file name contains accents
 or chinese chars, no?

-- 
Ticket URL: <http://core.trac.wordpress.org/ticket/9416#comment:27>
WordPress Trac <http://trac.wordpress.org/>
WordPress blogging software


More information about the wp-trac mailing list