[wp-trac] [WordPress Trac] #30300: setUserSetting js function only removes first unwanted character (was: setUserSetting js function only removes first unwanted charter)

WordPress Trac noreply at wordpress.org
Sun Nov 9 18:04:55 UTC 2014


#30300: setUserSetting js function only removes first unwanted character
----------------------------+------------------------------
 Reporter:  TV productions  |       Owner:
     Type:  defect (bug)    |      Status:  new
 Priority:  normal          |   Milestone:  Awaiting Review
Component:  Administration  |     Version:  trunk
 Severity:  normal          |  Resolution:
 Keywords:  has-patch       |     Focuses:  javascript
----------------------------+------------------------------
Changes (by TobiasBg):

 * keywords:   => has-patch


Old description:

> The function comments of the function setUserSetting in `wp-
> includes/js/utils.js` says the following: "Both name and value must be
> only ASCII letters, numbers or underscore (...)". The function removes
> the unwanted charters with the js `replace` function, in the current
> code, it only removes the first occurrence of an unwanted charter. This
> is solved by adding the `g` modifier to the replace regex. See the
> attached patch.
>
> How to reproduce:
> * Open your browsers console while you are logged in to your WordPress
> installation.
> * Run the following command: `setUserSetting('test--', 'bad-value-')`
> (note that the - charter is not allowed)
> * The console will return `"test-"` (not `"test"` as expected).
> * Run `getUserSetting('test-')`.
> * The console returns `"badvalue-"` (not `"badvalue"` as expected).
> * You may want to delete the setting by executing
> `deleteUserSetting('test-')`.

New description:

 The function comments of the function setUserSetting in `wp-
 includes/js/utils.js` says the following: "Both name and value must be
 only ASCII letters, numbers or underscore (...)". The function removes the
 unwanted characters with the js `replace` function, in the current code,
 it only removes the first occurrence of an unwanted character. This is
 solved by adding the `g` modifier to the replace regex. See the attached
 patch.

 How to reproduce:
 * Open your browsers console while you are logged in to your WordPress
 installation.
 * Run the following command: `setUserSetting('test--', 'bad-value-')`
 (note that the - character is not allowed)
 * The console will return `"test-"` (not `"test"` as expected).
 * Run `getUserSetting('test-')`.
 * The console returns `"badvalue-"` (not `"badvalue"` as expected).
 * You may want to delete the setting by executing
 `deleteUserSetting('test-')`.

--

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


More information about the wp-trac mailing list