encoding and decoding of vfs special characters

This commit is contained in:
Ralf Becker 2012-03-28 13:58:18 +00:00
parent 2f62d7e3b5
commit b55250b81a
2 changed files with 71 additions and 26 deletions

View File

@ -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')
@ -158,9 +158,13 @@ var et2_vfsName = et2_textbox.extend({
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"]);

View File

@ -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