From 1079cbb7a8bffcf950661169cb108d152c63db2e Mon Sep 17 00:00:00 2001 From: NoCLin Date: Mon, 30 Jul 2018 23:00:00 +0800 Subject: [PATCH 1/2] fix: allow relative path (#590) --- src/core/router/history/base.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) mode change 100644 => 100755 src/core/router/history/base.js diff --git a/src/core/router/history/base.js b/src/core/router/history/base.js old mode 100644 new mode 100755 index 0f9900d22..d89e3d567 --- a/src/core/router/history/base.js +++ b/src/core/router/history/base.js @@ -76,6 +76,11 @@ export class History { (idIndex > 0 ? currentRoute.substr(0, idIndex) : currentRoute) + path } - return cleanPath('/' + path) + if (currentRoute !== undefined) { + currentRoute = currentRoute.substr(0, currentRoute.lastIndexOf('/') + 1) + console.log(currentRoute, path) + } + + return cleanPath(path.startsWith('/') ? path : currentRoute + path) } } From bee0db865bda1704301ba5bacbd04ae8bb29d478 Mon Sep 17 00:00:00 2001 From: NoCLin Date: Tue, 31 Jul 2018 09:14:03 +0800 Subject: [PATCH 2/2] fix: resolve './' and '../' (#590) --- src/core/router/history/base.js | 13 ++++++++----- src/core/router/util.js | 16 ++++++++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/core/router/history/base.js b/src/core/router/history/base.js index d89e3d567..3d3b5b508 100755 --- a/src/core/router/history/base.js +++ b/src/core/router/history/base.js @@ -3,7 +3,8 @@ import { isAbsolutePath, stringifyQuery, cleanPath, - replaceSlug + replaceSlug, + resolvePath } from '../util' import {noop, merge} from '../../util/core' @@ -76,11 +77,13 @@ export class History { (idIndex > 0 ? currentRoute.substr(0, idIndex) : currentRoute) + path } - if (currentRoute !== undefined) { - currentRoute = currentRoute.substr(0, currentRoute.lastIndexOf('/') + 1) - console.log(currentRoute, path) + if (path.startsWith('/')) { + return cleanPath(path) } - return cleanPath(path.startsWith('/') ? path : currentRoute + path) + if (currentRoute !== undefined) { + const currentDir = currentRoute.substr(0, currentRoute.lastIndexOf('/') + 1) + return cleanPath(resolvePath(currentDir + path)) + } } } diff --git a/src/core/router/util.js b/src/core/router/util.js index 217461f47..117a090f4 100644 --- a/src/core/router/util.js +++ b/src/core/router/util.js @@ -60,3 +60,19 @@ export function getPath(...args) { export const replaceSlug = cached(path => { return path.replace('#', '?id=') }) + +export const resolvePath = cached(path => { + const segments = path.replace(/^\//, '').split('/') + let resolved = [] + + for (let i = 0, len = segments.length; i < len; i++) { + const segment = segments[i] + + if (segment === '..') { + resolved.pop() + } else if (segment !== '.') { + resolved.push(segment) + } + } + return '/' + resolved.join('/') +})