Skip to content

Commit c507d2c

Browse files
committed
fix(stringToParts): handle empty string and trailing dot the same way that split() does for backwards compat
Re: Automattic/mongoose#9681
1 parent 484c22c commit c507d2c

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

lib/stringToParts.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@ module.exports = function stringToParts(str) {
2525
curPropertyName += str[i];
2626
}
2727
}
28-
if (curPropertyName.length > 0) {
29-
result.push(curPropertyName);
30-
}
28+
result.push(curPropertyName);
3129

3230
return result;
3331
};

test/stringToParts.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,12 @@ describe('stringToParts', function() {
1717
it('throws for invalid numbers in square brackets', function() {
1818
assert.throws(() => stringToParts('foo[1mystring]'), /1mystring/);
1919
});
20+
21+
it('handles empty string', function() {
22+
assert.deepEqual(stringToParts(''), ['']);
23+
});
24+
25+
it('handles trailing dot', function() {
26+
assert.deepEqual(stringToParts('a.b.'), ['a', 'b', '']);
27+
});
2028
});

0 commit comments

Comments
 (0)