1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-07 09:51:26 +00:00
This commit is contained in:
Michael An
2019-06-20 18:03:26 +08:00
parent 08579289d7
commit eaca5e0584
2 changed files with 11 additions and 11 deletions

View File

@@ -140,7 +140,9 @@ class WikiMarkdownViewer extends React.Component {
let index2 = url.indexOf('?'); let index2 = url.indexOf('?');
imagePath = url.substring(index + 5, index2); imagePath = url.substring(index + 5, index2);
} else if (/^\.\.\/*/.test(url) || /^\.\/*/.test(url)) { } else if (/^\.\.\/*/.test(url) || /^\.\/*/.test(url)) {
imagePath = Utils.pathNormalize(this.props.path, url); const path = this.props.path;
const originalPath = path.slice(0, path.lastIndexOf('/')) + '/' + url;
imagePath = Utils.pathNormalize(originalPath);
} else { } else {
return; return;
} }

View File

@@ -880,20 +880,18 @@ export const Utils = {
return password; return password;
}, },
pathNormalize: function(filePath, relativePath) { pathNormalize: function(originalPath) {
let newPath = relativePath.split('/'); let newPath = originalPath.split('/');
let path = filePath.slice(1, filePath.lastIndexOf('/')).split('/'); for (let i = 0; i < newPath.length; i++) {
for (let i = 0, len = newPath.length; i < len; i++) { if (newPath[i] === '.' || newPath[i] === '') {
if (newPath[i] === '..') {
path.pop();
newPath.splice(i, 1);
i--;
} else if (newPath[i] === '.') {
newPath.splice(i, 1); newPath.splice(i, 1);
i--; i--;
} else if (newPath[i] === '..') {
newPath.splice(i - 1, 2);
i = i - 2;
} }
} }
return path.concat(newPath).join('/'); return newPath.join('/');
}, },
getEventData: function(event, data) { getEventData: function(event, data) {