diff --git a/frontend/src/components/wiki-markdown-viewer.js b/frontend/src/components/wiki-markdown-viewer.js index b9f16887e0..a6bf1b8948 100644 --- a/frontend/src/components/wiki-markdown-viewer.js +++ b/frontend/src/components/wiki-markdown-viewer.js @@ -140,7 +140,9 @@ class WikiMarkdownViewer extends React.Component { let index2 = url.indexOf('?'); imagePath = url.substring(index + 5, index2); } 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 { return; } diff --git a/frontend/src/utils/utils.js b/frontend/src/utils/utils.js index 360f4e7bb6..7346ec0598 100644 --- a/frontend/src/utils/utils.js +++ b/frontend/src/utils/utils.js @@ -880,20 +880,18 @@ export const Utils = { return password; }, - pathNormalize: function(filePath, relativePath) { - let newPath = relativePath.split('/'); - let path = filePath.slice(1, filePath.lastIndexOf('/')).split('/'); - for (let i = 0, len = newPath.length; i < len; i++) { - if (newPath[i] === '..') { - path.pop(); - newPath.splice(i, 1); - i--; - } else if (newPath[i] === '.') { + pathNormalize: function(originalPath) { + let newPath = originalPath.split('/'); + for (let i = 0; i < newPath.length; i++) { + if (newPath[i] === '.' || newPath[i] === '') { newPath.splice(i, 1); 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) {