diff --git a/index.js b/index.js index 62044a4..0cadf78 100644 --- a/index.js +++ b/index.js @@ -50,7 +50,7 @@ var blacklistFilter = function (part) { return blacklist.indexOf(part) === -1 } function parsePath (path, sep) { if (path.indexOf('[') >= 0) { - path = path.replace(/\[/g, '.').replace(/]/g, '') + path = path.replace(/\[/g, sep).replace(/]/g, '') } var parts = path.split(sep) diff --git a/src/dot-object.js b/src/dot-object.js index 6a3a0e5..1129746 100644 --- a/src/dot-object.js +++ b/src/dot-object.js @@ -50,7 +50,7 @@ var blacklistFilter = function (part) { return blacklist.indexOf(part) === -1 } function parsePath (path, sep) { if (path.indexOf('[') >= 0) { - path = path.replace(/\[/g, '.').replace(/]/g, '') + path = path.replace(/\[/g, sep).replace(/]/g, '') } var parts = path.split(sep) diff --git a/test/dot-json.js b/test/dot-json.js index edfafb1..84f28c0 100644 --- a/test/dot-json.js +++ b/test/dot-json.js @@ -55,6 +55,28 @@ describe('Object test:', function () { }) }) + it('Should expand dotted keys with array notation with different separator', function () { + var row = { + id: 2, + my_arr_0: 'one', + my_arr_1: 'two', + my_arr_2: 'three', + 'my_arr2[0]': 'one', + 'my_arr2[1]': 'two', + 'my_arr2[2]': 'three' + } + + new Dot('_').object(row) + + row.should.eql({ + id: 2, + my: { + arr: ['one', 'two', 'three'], + arr2: ['one', 'two', 'three'] + } + }) + }) + it('Should allow keys with numbers', function () { var row = { id: 2,