diff --git a/src/util/scroll.js b/src/util/scroll.js index d1adeb310..6dfd92750 100644 --- a/src/util/scroll.js +++ b/src/util/scroll.js @@ -4,6 +4,7 @@ import type Router from '../index' import { assert } from './warn' import { getStateKey, setStateKey } from './state-key' import { extend } from './misc' +import { cleanPath } from './path' const positionStore = Object.create(null) @@ -22,7 +23,8 @@ export function setupScroll () { // preserve existing history state as it could be overriden by the user const stateCopy = extend({}, window.history.state) stateCopy.key = getStateKey() - window.history.replaceState(stateCopy, '', absolutePath) + // Fix for #2593 clean path to avoid crashing entire app on paths with leading double-slash (http://example.com//foo/bar) + window.history.replaceState(stateCopy, '', cleanPath(absolutePath)) window.addEventListener('popstate', handlePopState) return () => { window.removeEventListener('popstate', handlePopState) diff --git a/test/e2e/specs/scroll-behavior.js b/test/e2e/specs/scroll-behavior.js index d7469e9e0..b67feee73 100644 --- a/test/e2e/specs/scroll-behavior.js +++ b/test/e2e/specs/scroll-behavior.js @@ -9,6 +9,7 @@ module.exports = { const TIMEOUT = 2000 browser + .url('http://localhost:8080/scroll-behavior/') .waitForElementVisible('#app', 1000) .assert.count('li a', 6) @@ -138,6 +139,15 @@ module.exports = { 'scroll to anchor on load' ) + // #2593 no crash on malformed URL + .url('http://localhost:8080//scroll-behavior') + .execute(function () { + location.reload(true) + }) + .waitForElementVisible('#app', 1000) + .assert.count('li a', 6) + .assert.containsText('.view', 'home') + .end() } }