diff --git a/common/cloudfunc.js b/common/cloudfunc.js
index e682a520..b075ea9d 100644
--- a/common/cloudfunc.js
+++ b/common/cloudfunc.js
@@ -23,6 +23,7 @@ module.exports.MAX_FILE_SIZE = 500 * 1024;
module.exports.Entity = Entity;
module.exports.getHeaderField = getHeaderField;
module.exports.getPathLink = getPathLink;
+module.exports.getDotDot = getDotDot;
module.exports.formatMsg = (msg, name, status) => {
status = status || 'ok';
@@ -152,12 +153,9 @@ module.exports.buildFromJSON = (params) => {
fileTable += header + '
';
/* Если мы не в корне */
- if (path !== '/') {
- /* убираем последний слеш и каталог в котором мы сейчас находимся*/
- const lastSlash = path.substr(path, path.lastIndexOf('/'));
- const dotDot = lastSlash.substr(lastSlash, lastSlash.lastIndexOf('/'));
-
- const link = prefix + FS + (dotDot || '/');
+ if (path !== '/') {
+ const dotDot = getDotDot(path);
+ const link = prefix + FS + dotDot;
const linkResult = rendy(template.link, {
link,
@@ -253,3 +251,14 @@ function _getHeaderField(sort, order, name) {
return `${name}${arrow}`;
}
+function getDotDot(path) {
+ // убираем последний слеш и каталог в котором мы сейчас находимся
+ const lastSlash = path.substr(path, path.lastIndexOf('/'));
+ const dotDot = lastSlash.substr(lastSlash, lastSlash.lastIndexOf('/'));
+
+ if (!dotDot)
+ return '/';
+
+ return dotDot;
+}
+
diff --git a/test/common/cloudfunc.js b/test/common/cloudfunc.js
index ea0f4f90..c3467eda 100644
--- a/test/common/cloudfunc.js
+++ b/test/common/cloudfunc.js
@@ -213,3 +213,18 @@ test('cloudfunc: getPathLink: no template', (t) => {
t.end();
});
+test('cloudfunc: getDotDot', (t) => {
+ const dotDot = CloudFunc.getDotDot('/home');
+
+ t.equal(dotDot, '/', 'should return root');
+ t.end();
+});
+
+test('cloudfunc: getDotDot: two levels deep', (t) => {
+ const dotDot = CloudFunc.getDotDot('/home/coderaiser/');
+ console.log(dotDot);
+
+ t.equal(dotDot, '/home', 'should return up level');
+ t.end();
+});
+