From 2b2a9400d384abbdc178accae7366b75f95e9b75 Mon Sep 17 00:00:00 2001 From: Kory Nunn Date: Mon, 2 Dec 2013 15:45:11 +1000 Subject: [PATCH] more edgecase checks --- paths.js | 10 ++++++---- test/all.js | 28 +++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 7 deletions(-) diff --git a/paths.js b/paths.js index 5011e6c..2f74b3d 100644 --- a/paths.js +++ b/paths.js @@ -141,12 +141,14 @@ function createRootPath(){ } function pathToParts(path){ - if(!path && typeof path !== 'string'){ + var pathType = typeof path; + + if(pathType !== 'string' && pathType !== 'number'){ + if(Array.isArray(path)){ + return path; + } return; } - if(Array.isArray(path)){ - return path; - } // if we haven't been passed a path, then turn the input into a path if (!isPath(path)) { diff --git a/test/all.js b/test/all.js index dd740b7..69bdc2d 100644 --- a/test/all.js +++ b/test/all.js @@ -208,7 +208,7 @@ test('bubble capturing path with bubble capture as only child key', function(t) ); }); -test('to parts', function(t) { +test('to parts valid path', function(t) { var path = '[a/b/c]' t.plan(1); @@ -219,7 +219,7 @@ test('to parts', function(t) { ); }); -test('to parts', function(t) { +test('to parts valid key', function(t) { var path = 'a'; t.plan(1); @@ -230,7 +230,7 @@ test('to parts', function(t) { ); }); -test('to parts', function(t) { +test('to parts invalid key', function(t) { var path = 'a[b]'; t.plan(1); @@ -239,4 +239,26 @@ test('to parts', function(t) { paths.toParts(path), 'no valid path' ); +}); + +test('to parts boolean', function(t) { + var path = true; + + t.plan(1); + + t.notOk( + paths.toParts(path), + 'true is not a path' + ); +}); + +test('to parts boolean', function(t) { + var path = false; + + t.plan(1); + + t.notOk( + paths.toParts(path), + 'false is not a path' + ); }); \ No newline at end of file