Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix nested object comparison for queries #1425

Merged
merged 1 commit into from
Jun 16, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix nested object comparison for queries
Fix #1421
  • Loading branch information
posva committed May 17, 2017
commit 1fe1ce027769341032c94cd98edd3c332923d9ed
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