From b55250b81a91cc1234fee47be168b0159e9e30ee Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Wed, 28 Mar 2012 13:58:18 +0000 Subject: [PATCH] encoding and decoding of vfs special characters --- etemplate/js/et2_widget_vfs.js | 54 ++++++++++++++++++---------------- phpgwapi/js/jsapi/egw_utils.js | 43 ++++++++++++++++++++++++++- 2 files changed, 71 insertions(+), 26 deletions(-) diff --git a/etemplate/js/et2_widget_vfs.js b/etemplate/js/et2_widget_vfs.js index 82c60edcba..f957ca9968 100644 --- a/etemplate/js/et2_widget_vfs.js +++ b/etemplate/js/et2_widget_vfs.js @@ -77,7 +77,7 @@ var et2_vfs = et2_valueWidget.extend([et2_IDetachedDOM], { var text; for(var i = 0; i < path_parts.length; i++) { - text = path_parts[i]; + text = decodeURIComponent(path_parts[i]); // Nice human-readable stuff for apps if(path_parts[1] == 'apps') @@ -121,26 +121,26 @@ var et2_vfs = et2_valueWidget.extend([et2_IDetachedDOM], { }, /** - * Code for implementing et2_IDetachedDOM (data grid) - */ - getDetachedAttributes: function(_attrs) - { - _attrs.push("value"); - }, + * Code for implementing et2_IDetachedDOM (data grid) + */ + getDetachedAttributes: function(_attrs) + { + _attrs.push("value"); + }, - getDetachedNodes: function() - { - return [this.span[0]]; - }, + getDetachedNodes: function() + { + return [this.span[0]]; + }, - setDetachedAttributes: function(_nodes, _values) - { - this.span = jQuery(_nodes[0]); - if(typeof _values["value"] != 'undefined') - { - this.set_value(_values["value"]); - } - } + setDetachedAttributes: function(_nodes, _values) + { + this.span = jQuery(_nodes[0]); + if(typeof _values["value"] != 'undefined') + { + this.set_value(_values["value"]); + } + } }); @@ -152,15 +152,19 @@ et2_register_widget(et2_vfs, ["vfs"]); */ var et2_vfsName = et2_textbox.extend({ init: function() { - this._super.apply(this, arguments); + this._super.apply(this, arguments); this.input.addClass("et2_vfs"); }, set_value: function(_value) { if(_value.path) { - _value = _value.path + _value = _value.path; } + _value = egw.decodePath(_value); this._super.apply(this,[_value]); + }, + getValue: function() { + return egw.encodePath(this._super.apply(this)); } }); et2_register_widget(et2_vfsName, ["vfs-name"]); @@ -183,7 +187,7 @@ var et2_vfsMime = et2_valueWidget.extend([et2_IDetachedDOM], { }, init: function() { - this._super.apply(this, arguments); + this._super.apply(this, arguments); this.image = jQuery(document.createElement("img")); this.image.addClass("et2_vfs vfsMimeIcon"); this.setDOMNode(this.image[0]); @@ -262,7 +266,7 @@ var et2_vfsSize = et2_description.extend({ jQuery(this.node).text(this.human_size(_value)); }, setDetachedAttributes: function(_nodes, _values) - { + { if(typeof _values["value"] !== "undefined") { this.node = _nodes[0]; this.set_value(_values["value"]); @@ -301,7 +305,7 @@ var et2_vfsMode = et2_description.extend({ 'r': 0x4 // Read }, init: function() { - this._super.apply(this, arguments); + this._super.apply(this, arguments); this.span.addClass("et2_vfs"); }, @@ -367,7 +371,7 @@ var et2_vfsMode = et2_description.extend({ }, setDetachedAttributes: function(_nodes, _values) - { + { if(typeof _values["value"] !== "undefined") { this.node = _nodes[0]; this.set_value(_values["value"]); diff --git a/phpgwapi/js/jsapi/egw_utils.js b/phpgwapi/js/jsapi/egw_utils.js index 9f8a7f27d4..fc6ea14ce7 100644 --- a/phpgwapi/js/jsapi/egw_utils.js +++ b/phpgwapi/js/jsapi/egw_utils.js @@ -162,8 +162,49 @@ egw.extend('utils', egw.MODULE_GLOBAL, function() { uid: function() { return (uid_counter++).toString(16); - } + }, + /** + * Decode encoded vfs special chars + * + * @param string _path path to decode + * @return string + */ + decodePath: function(_path) { + return decodeURIComponent(_path); + }, + + /** + * Encode vfs special chars excluding / + * + * @param string _path path to decode + * @return string + */ + encodePath: function(_path) { + var components = _path.split('/'); + for(var n=0; n < components.length; n++) + { + components[n] = this.encodePathComponent(components[n]); + } + return components.join('/'); + }, + + /** + * Encode vfs special chars removing / + * + * //'%' => '%25', // % should be encoded, but easily leads to double encoding, therefore better NOT encodig it + * '#' => '%23', + * '?' => '%3F', + * '/' => '', // better remove it completly + * + * @param string _path path to decode + * @return string + */ + /* + */ + encodePathComponent: function(_comp) { + return _comp.replace(/#/g,'%23').replace(/\?/g,'%3F').replace(/\//g,''); + } }; // Check whether the browser already supports encoding JSON -- if yes, use