[wp-trac] [WordPress Trac] #22781: setUserSetting cannot handle hyphens

WordPress Trac noreply at wordpress.org
Fri Jun 14 23:24:14 UTC 2013


#22781: setUserSetting cannot handle hyphens
--------------------------+-----------------------------
 Reporter:  nacin         |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Future Release
Component:  General       |     Version:  2.7
 Severity:  normal        |  Resolution:
 Keywords:  3.6-early     |
--------------------------+-----------------------------

Comment (by cbaldelomar):

 I just came across this bug in my plugin development. The bug occurs on
 line 147 of the file /wp-includes/js/utils.js

 {{{
 n = name.toString().replace(/[^A-Za-z0-9_]/, ''), v =
 value.toString().replace(/[^A-Za-z0-9_]/, '');
 }}}

 To fix this problem, we will need to add a hypen to the regular expression
 list when storing to variable {v}.
 {{{
 n = name.toString().replace(/[^A-Za-z0-9_]/, ''), v =
 value.toString().replace(/[^A-Za-z0-9_-]/, '');
 }}}

 It is also interesting to note that this javascript replace method will
 only replace the first occurrence of the string. So if I added an image
 size with the name "my-custom-image-size", the original line of code would
 return "mycustom-image-size". I do not think this would have been the
 developers intended purpose. This can be easily fixed by adding the 'g'
 flag in the replace function.
 {{{
 n = name.toString().replace(/[^A-Za-z0-9_]/g, ''), v =
 value.toString().replace(/[^A-Za-z0-9_-]/g, '');
 }}}

 I would be more than happy to submit my very first patch to the Wordpress
 core. However, I'm not sure if this needs to be discussed more as an
 acceptable solution. What do you all think?

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


More information about the wp-trac mailing list