Skip to content

Commit 4b926e3

Browse files
committed
fix(query): check existing keys
Fix #3341
1 parent 64d60c0 commit 4b926e3

File tree

4 files changed

+200
-88
lines changed

4 files changed

+200
-88
lines changed

package.json

+7-7
Original file line numberDiff line numberDiff line change
@@ -68,13 +68,13 @@
6868
"babel-plugin-syntax-dynamic-import": "^6.18.0",
6969
"babel-preset-env": "^1.6.1",
7070
"babel-preset-flow-vue": "^1.0.0",
71-
"browserstack-local": "^1.4.0",
71+
"browserstack-local": "^1.4.8",
7272
"buble": "^0.19.8",
73-
"chromedriver": "^83.0.0",
73+
"chromedriver": "^86.0.0",
7474
"conventional-changelog-cli": "^2.0.11",
75-
"cross-spawn": "^6.0.5",
75+
"cross-spawn": "^7.0.3",
7676
"css-loader": "^2.1.1",
77-
"dotenv": "^8.0.0",
77+
"dotenv": "^8.2.0",
7878
"es6-promise": "^4.2.8",
7979
"eslint": "^4.19.1",
8080
"eslint-plugin-flowtype": "^2.46.1",
@@ -83,7 +83,7 @@
8383
"express": "^4.17.1",
8484
"express-urlrewrite": "^1.2.0",
8585
"flow-bin": "^0.66.0",
86-
"geckodriver": "^1.19.1",
86+
"geckodriver": "^1.20.0",
8787
"jasmine": "2.8.0",
8888
"lint-staged": "^8.2.0",
8989
"nightwatch": "^1.3.6",
@@ -99,9 +99,9 @@
9999
"selenium-server": "^3.141.59",
100100
"terser": "^4.2.0",
101101
"typescript": "^3.5.2",
102-
"vue": "^2.6.11",
102+
"vue": "^2.6.12",
103103
"vue-loader": "^15.9.3",
104-
"vue-template-compiler": "^2.6.11",
104+
"vue-template-compiler": "^2.6.12",
105105
"vuepress": "^1.5.3",
106106
"vuepress-theme-vue": "^1.1.1",
107107
"webpack": "^4.35.2",

src/util/route.js

+5-3
Original file line numberDiff line numberDiff line change
@@ -96,13 +96,15 @@ export function isSameRoute (a: Route, b: ?Route): boolean {
9696
function isObjectEqual (a = {}, b = {}): boolean {
9797
// handle null value #1566
9898
if (!a || !b) return a === b
99-
const aKeys = Object.keys(a)
100-
const bKeys = Object.keys(b)
99+
const aKeys = Object.keys(a).sort()
100+
const bKeys = Object.keys(b).sort()
101101
if (aKeys.length !== bKeys.length) {
102102
return false
103103
}
104-
return aKeys.every(key => {
104+
return aKeys.every((key, i) => {
105105
const aVal = a[key]
106+
const bKey = bKeys[i]
107+
if (bKey !== key) return false
106108
const bVal = b[key]
107109
// query values can be null and undefined
108110
if (aVal == null || bVal == null) return aVal === bVal

test/unit/specs/route.spec.js

+26-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ describe('Route utils', () => {
99
query: { foo: 'bar', arr: [1, 2] }
1010
}
1111
const b = {
12-
path: '/a/', // Allow trailing slash
12+
path: '/a/', // Allow trailing slash
1313
hash: '#hi',
1414
query: { arr: ['1', '2'], foo: 'bar' }
1515
}
@@ -66,6 +66,31 @@ describe('Route utils', () => {
6666
expect(isSameRoute(a, b)).toBe(true)
6767
expect(isSameRoute(a, c)).toBe(false)
6868
})
69+
70+
it('queries with undefined values', () => {
71+
const a = {
72+
path: '/abc',
73+
query: { a: 'x' }
74+
}
75+
const b = {
76+
path: '/abc',
77+
query: { id: undefined }
78+
}
79+
const c = {
80+
path: '/abc',
81+
query: {}
82+
}
83+
expect(() => isSameRoute(a, b)).not.toThrow()
84+
expect(() => isSameRoute(a, c)).not.toThrow()
85+
expect(() => isSameRoute(b, c)).not.toThrow()
86+
expect(isSameRoute(a, b)).toBe(false)
87+
expect(isSameRoute(a, c)).toBe(false)
88+
// NOTE: in reality this should be true but because we check queries as
89+
// objects, they are different objects. We should check queries as their
90+
// string representation instead
91+
expect(isSameRoute(b, c)).toBe(false)
92+
expect(isSameRoute(c, b)).toBe(false)
93+
})
6994
})
7095

7196
describe('isIncludedRoute', () => {

0 commit comments

Comments
 (0)