Skip to content

Commit

Permalink
#128 fix LF and CR in SpreadsheetCell.save
Browse files Browse the repository at this point in the history
1. fixed `xmlSafeValue` function to escpae LF and CR
2. added test to `cells-test.js`
  • Loading branch information
yfp committed Jul 8, 2016
1 parent 5a52afa commit 12b7acc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
4 changes: 3 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,9 @@ var xmlSafeValue = function(val){
return String(val).replace(/&/g, '&')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
.replace(/"/g, '&quot;')
.replace(/\n/g,'&#10;')
.replace(/\r/g,'&#13;');
}
var xmlSafeColumnName = function(val){
if (!val) return '';
Expand Down
11 changes: 11 additions & 0 deletions test/cells-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,17 @@ describe('Cell-based feeds', function() {
});
});

it('can update a single cell with linefeed in value', function(done) {
cell.setValue('HELLO\nWORLD', function(err) {
(!err).should.be.true;
cell.value.should.equal('HELLO\nWORLD');
sheet.getCells({}, function(err, cells) {
cells[0].value.should.equal('HELLO\nWORLD');
done(err);
});
});
});

it('supports `value` to numeric values', function(done) {
cell.value = 123;
cell.value.should.equal('123');
Expand Down

0 comments on commit 12b7acc

Please sign in to comment.