Skip to content

Commit

Permalink
modify the handling of invalid names in getPath, returning empty stri…
Browse files Browse the repository at this point in the history
…ng for invalid name item
  • Loading branch information
vedkribhu committed Oct 17, 2023
1 parent 3ac1177 commit 6d24c87
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 8 deletions.
12 changes: 5 additions & 7 deletions lib/collection/item.js
Original file line number Diff line number Diff line change
Expand Up @@ -337,16 +337,14 @@ _.assign(Item.prototype, /** @lends Item.prototype */ {
* @returns {Array<string>}
*/
getPath: function () {
const path = [];

if (typeof this.name === 'string') {
const pushItem = (item) => {
const path = [],
pushItem = (item) => {
path.push(item.name || '');
};

pushItem(this);
this.forEachParent({ withRoot: true }, pushItem);
}
pushItem(this);
this.forEachParent({ withRoot: true }, pushItem);


return path.reverse();
}
Expand Down
2 changes: 1 addition & 1 deletion test/unit/item.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ describe('Item', function () {
f1 = collection.items.members[0],
r1 = f1.items.members[0];

expect(r1.getPath()).to.deep.equal([]);
expect(r1.getPath()).to.deep.equal(['', '', '']);
});
});

Expand Down

0 comments on commit 6d24c87

Please sign in to comment.