Skip to content

Commit

Permalink
Fix nested object comparison for queries (#1425)
Browse files Browse the repository at this point in the history
Fix #1421
  • Loading branch information
posva authored and yyx990803 committed Jun 16, 2017
1 parent 27247b7 commit fd2fb67
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/util/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,15 @@ function isObjectEqual (a = {}, b = {}): boolean {
if (aKeys.length !== bKeys.length) {
return false
}
return aKeys.every(key => String(a[key]) === String(b[key]))
return aKeys.every(key => {
const aVal = a[key]
const bVal = b[key]
// check nested equality
if (typeof aVal === 'object' && typeof bVal === 'object') {
return isObjectEqual(aVal, bVal)
}
return String(aVal) === String(bVal)
})
}

export function isIncludedRoute (current: Route, target: Route): boolean {
Expand Down
17 changes: 17 additions & 0 deletions test/unit/specs/route.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,23 @@ describe('Route utils', () => {
}
expect(isSameRoute(a, b)).toBe(true)
})

it('nested query', () => {
const a = {
path: '/abc',
query: { foo: { bar: 'bar' }, arr: [1, 2] }
}
const b = {
path: '/abc',
query: { arr: [1, 2], foo: { bar: 'bar' } }
}
const c = {
path: '/abc',
query: { arr: [1, 2], foo: { bar: 'not bar' } }
}
expect(isSameRoute(a, b)).toBe(true)
expect(isSameRoute(a, c)).toBe(false)
})
})

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

0 comments on commit fd2fb67

Please sign in to comment.