From 4e95bd8039e75cc8cd10eeebebedca23d7a0197c Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Wed, 11 Oct 2017 22:08:40 +0200 Subject: [PATCH] fix: handle null values when comparing objects (#1568) Fix #1566 --- src/util/route.js | 2 ++ test/unit/specs/route.spec.js | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/util/route.js b/src/util/route.js index 9fee9c099..c87dfe8a8 100644 --- a/src/util/route.js +++ b/src/util/route.js @@ -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) { diff --git a/test/unit/specs/route.spec.js b/test/unit/specs/route.spec.js index e15f550f4..8e8118537 100644 --- a/test/unit/specs/route.spec.js +++ b/test/unit/specs/route.spec.js @@ -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', () => {