Skip to content

Commit

Permalink
fix: handle null values when comparing objects (#1568)
Browse files Browse the repository at this point in the history
Fix #1566
  • Loading branch information
posva authored and yyx990803 committed Oct 11, 2017
1 parent 1422eb5 commit 4e95bd8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/util/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ export function isSameRoute (a: Route, b: ?Route): boolean {
}

function isObjectEqual (a = {}, b = {}): boolean {
// handle null value #1566
if (!a || !b) return a === b
const aKeys = Object.keys(a)
const bKeys = Object.keys(b)
if (aKeys.length !== bKeys.length) {
Expand Down
19 changes: 19 additions & 0 deletions test/unit/specs/route.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,25 @@ describe('Route utils', () => {
expect(isSameRoute(a, b)).toBe(true)
expect(isSameRoute(a, c)).toBe(false)
})

it('queries with null values', () => {
const a = {
path: '/abc',
query: { foo: null }
}
const b = {
path: '/abc',
query: { foo: null }
}
const c = {
path: '/abc',
query: { foo: 5 }
}
expect(() => isSameRoute(a, b)).not.toThrow()
expect(() => isSameRoute(a, c)).not.toThrow()
expect(isSameRoute(a, b)).toBe(true)
expect(isSameRoute(a, c)).toBe(false)
})
})

describe('isIncludedRoute', () => {
Expand Down

0 comments on commit 4e95bd8

Please sign in to comment.