Skip to content

Commit

Permalink
Handle carriage returns in lines()
Browse files Browse the repository at this point in the history
Closes #305 #335
  • Loading branch information
esamattis committed Dec 21, 2014
1 parent ce7693c commit b217645
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lines.js
@@ -1,4 +1,4 @@
module.exports = function lines(str) {
if (str == null) return [];
return String(str).split('\n');
return String(str).split(/\r?\n/);
};
2 changes: 2 additions & 0 deletions test/strings.js
Expand Up @@ -533,6 +533,8 @@ $(document).ready(function() {
deepEqual(_('').lines(), ['']);
deepEqual(_(null).lines(), []);
deepEqual(_(undefined).lines(), []);
deepEqual(_('Hello\rWorld').lines(), ['Hello\rWorld']);
deepEqual(_('Hello\r\nWorld').lines(), ['Hello', 'World']);
});

test('String: pad', function() {
Expand Down

0 comments on commit b217645

Please sign in to comment.