Skip to content

Commit 4e95bd8

Browse files
posvayyx990803
authored andcommitted
fix: handle null values when comparing objects (#1568)
Fix #1566
1 parent 1422eb5 commit 4e95bd8

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

src/util/route.js

+2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ export function isSameRoute (a: Route, b: ?Route): boolean {
7474
}
7575

7676
function isObjectEqual (a = {}, b = {}): boolean {
77+
// handle null value #1566
78+
if (!a || !b) return a === b
7779
const aKeys = Object.keys(a)
7880
const bKeys = Object.keys(b)
7981
if (aKeys.length !== bKeys.length) {

test/unit/specs/route.spec.js

+19
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,25 @@ describe('Route utils', () => {
4747
expect(isSameRoute(a, b)).toBe(true)
4848
expect(isSameRoute(a, c)).toBe(false)
4949
})
50+
51+
it('queries with null values', () => {
52+
const a = {
53+
path: '/abc',
54+
query: { foo: null }
55+
}
56+
const b = {
57+
path: '/abc',
58+
query: { foo: null }
59+
}
60+
const c = {
61+
path: '/abc',
62+
query: { foo: 5 }
63+
}
64+
expect(() => isSameRoute(a, b)).not.toThrow()
65+
expect(() => isSameRoute(a, c)).not.toThrow()
66+
expect(isSameRoute(a, b)).toBe(true)
67+
expect(isSameRoute(a, c)).toBe(false)
68+
})
5069
})
5170

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

0 commit comments

Comments
 (0)