diff --git a/src/util.js b/src/util.js index 8bd989c9..3f4f8663 100644 --- a/src/util.js +++ b/src/util.js @@ -30,12 +30,12 @@ export function exec(url, route, opts) { flags = (route[i].match(/[+*?]+$/) || EMPTY)[0] || '', plus = ~flags.indexOf('+'), star = ~flags.indexOf('*'), - val = url[i] || ''; + val = url[i]; if (!val && !star && (flags.indexOf('?')<0 || plus)) { ret = false; break; } - matches[param] = decodeURIComponent(val); + matches[param] = decodeURIComponent(val) || undefined; if (plus || star) { matches[param] = url.slice(i).map(decodeURIComponent).join('/'); break; diff --git a/test/util.test.js b/test/util.test.js index 04eab7d7..6743c8c6 100644 --- a/test/util.test.js +++ b/test/util.test.js @@ -85,10 +85,10 @@ describe('util', () => { }); it('should match optional param segments', () => { - expect(exec('/', '/:foo?', {})).toEqual({ foo:'' }); + expect(exec('/', '/:foo?', {})).toEqual({ foo:undefined }); expect(exec('/bar', '/:foo?', {})).toEqual({ foo:'bar' }); - expect(exec('/', '/:foo?/:bar?', {})).toEqual({ foo:'', bar:'' }); - expect(exec('/bar', '/:foo?/:bar?', {})).toEqual({ foo:'bar', bar:'' }); + expect(exec('/', '/:foo?/:bar?', {})).toEqual({ foo:undefined, bar:undefined }); + expect(exec('/bar', '/:foo?/:bar?', {})).toEqual({ foo:'bar', bar:undefined }); expect(exec('/bar', '/:foo?/bar', {})).toEqual(false); expect(exec('/foo/bar', '/:foo?/bar', {})).toEqual({ foo:'foo' }); });