mirror of
https://github.com/drakkan/sftpgo.git
synced 2025-12-07 23:00:55 +03:00
WebClient: cleanup some js code
also returns an error if file or directory names contain a slash instead of silently replacing slashes with a similar symbol Signed-off-by: Nicola Murino <nicola.murino@gmail.com>
This commit is contained in:
@@ -72,46 +72,13 @@ explicit grant from the SFTPGo Team (support@sftpgo.com).
|
||||
|
||||
{{- define "basejs"}}
|
||||
<script type="text/javascript" {{- if .}} nonce="{{.}}"{{- end}}>
|
||||
// https://developer.mozilla.org/en-US/docs/Web/API/Document/createTextNode
|
||||
function escapeHTML(str) {
|
||||
var div = document.createElement('div');
|
||||
div.appendChild(document.createTextNode(str));
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
function unescapeHTML(escapedStr) {
|
||||
var div = document.createElement('div');
|
||||
div.innerHTML = escapedStr;
|
||||
var child = div.childNodes[0];
|
||||
return child ? child.nodeValue : '';
|
||||
}
|
||||
|
||||
function escapeHTMLForceSafe(str) {
|
||||
return str
|
||||
.replace(/&/g, '_')
|
||||
.replace(/</g, '_')
|
||||
.replace(/>/g, '_')
|
||||
.replace(/\"/g, '_')
|
||||
.replace(/\'/g, '_');
|
||||
}
|
||||
|
||||
function fixedEncodeURIComponent(str) {
|
||||
return encodeURIComponent(unescapeHTML(str)).replace(/[!'()*]/g, function (c) {
|
||||
return '%' + c.charCodeAt(0).toString(16);
|
||||
});
|
||||
}
|
||||
|
||||
function replaceSlash(str){
|
||||
return str.replace(/\//g,'\u2215');
|
||||
}
|
||||
|
||||
function b64EncodeUnicode(str) {
|
||||
return btoa(encodeURIComponent(str));
|
||||
}
|
||||
|
||||
function UnicodeDecodeB64(str) {
|
||||
return decodeURIComponent(atob(str));
|
||||
}
|
||||
|
||||
function fileSizeIEC(a,b,c,d,e){
|
||||
return (b=Math,c=b.log,d=1024,e=c(a)/c(d)|0,a/b.pow(d,e)).toFixed(1)
|
||||
+' '+(e?'KMGTPEZY'[--e]+'iB':'Bytes')
|
||||
|
||||
Reference in New Issue
Block a user