Opened 5 years ago
Closed 5 years ago
#1485472 closed Bugs (fixed)
folder name of "new" confuses JS parser in IE 7 and Opera 9
| Reported by: | tensor | Owned by: | |
|---|---|---|---|
| Priority: | 5 | Milestone: | 0.2-stable |
| Component: | User Interface | Version: | 0.2-beta |
| Severity: | normal | Keywords: | |
| Cc: |
Description
If I create the folder with the name "new", IE 7 and Opera 9.60 beta 1 give a JS error.
They try to interpret rcmail.set_env() argument and fail on "new:{id:'new',name:'new',virtual:0}}" part, because the "new" token is a keyword.
As a result I cannot select any message.
FF 3 does not treat "new" as keyword and works without any problem.
Change History (2)
comment:1 Changed 5 years ago by tensor
comment:2 Changed 5 years ago by alec
- Resolution set to fixed
- Status changed from new to closed
Fixed in [c02bb9c3].
Note: See
TracTickets for help on using
tickets.

Here is a patch:
=== program/include/rcube_shared.inc ================================================================== --- program/include/rcube_shared.inc (revision 2024) +++ program/include/rcube_shared.inc (local) @@ -145,7 +145,7 @@ foreach ($var as $key => $value) { // enclose key with quotes if it is not variable-name conform - if (!ereg("^[_a-zA-Z]{1}[_a-zA-Z0-9]*$", $key) /* || is_js_reserved_word($key) */) + if (!ereg("^[_a-zA-Z]{1}[_a-zA-Z0-9]*$", $key) || is_js_reserved_word($key)) $key = "'$key'"; $pairs[] = sprintf("%s%s", $is_assoc ? "$key:" : '', json_serialize($value)); @@ -164,6 +164,30 @@ } /** + * Returns whether an $str is a reserved word for any of the version of Javascript or ECMAScript + * @param str String to check + * @return boolean True if $str is a reserver word, False if not + */ +function is_js_reserved_word($str) +{ + return in_array($str, array( + // ECMASript ver 4 reserved words + 'as','break','case','catch','class','const','continue', + 'default','delete','do','else','export','extends','false','finally','for','function', + 'if','import','in','instanceof','is','namespace','new','null','package','private', + 'public','return','super','switch','this','throw','true','try','typeof','use','var', + 'void','while','with', + // ECMAScript ver 4 future reserved words + 'abstract','debugger','enum','goto','implements','interface','native','protected', + 'synchronized','throws','transient','volatile', + // special meaning in some contexts + 'get','set', + // were reserved in ECMAScript ver 3 + 'boolean','byte','char','double','final','float','int','long','short','static' + )); +} + +/** * Function to convert an array to a javascript array * Actually an alias function for json_serialize() * @deprecated