Skip to content

Commit f7f9d23

Browse files
committed
Merge branch 'Icydillic-patch-2'
2 parents b0ef4b9 + 658629e commit f7f9d23

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

src/ng-csv/services/csv-service.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ angular.module('ngCsv.services').
55
service('CSV', ['$q', function ($q) {
66

77
var EOL = '\r\n';
8-
var BOM = "%ef%bb%bf";
8+
var BOM = "\ufeff";
99

1010
/**
1111
* Stringify one field
@@ -58,12 +58,12 @@ angular.module('ngCsv.services').
5858
csvContent += headerString + EOL;
5959
}
6060

61-
var arrData;
61+
var arrData = [];
6262

6363
if (angular.isArray(responseData)) {
6464
arrData = responseData;
6565
}
66-
else {
66+
else if (angular.isFunction(responseData)) {
6767
arrData = responseData();
6868
}
6969

test/unit/ngCsv/directives/ngCsv.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ describe('ngCsv directive', function () {
180180

181181
// Check that the compiled element contains the templated content
182182
scope.buildCSV(scope.data).then(function() {
183-
expect(scope.csv).toBe('%ef%bb%bf1,2,3\r\n4,5,6\r\n');
183+
expect(scope.csv).toBe('\ufeff1,2,3\r\n4,5,6\r\n');
184184
done();
185185
});
186186
scope.$apply();
@@ -323,4 +323,24 @@ describe('ngCsv directive', function () {
323323
$timeout.flush();
324324
scope.$apply();
325325
});
326+
327+
it('Handles undefined variables without raising any exception', function (done) {
328+
var element = $compile(
329+
'<div ng-csv="undefinedVariable" field-separator="{{sep}}"' +
330+
' filename="custom.csv">' +
331+
'</div>')($rootScope);
332+
$rootScope.$digest();
333+
$rootScope.sep = ';';
334+
$rootScope.$digest();
335+
336+
var scope = element.isolateScope();
337+
// Check that the compiled element has indeed undefined variable
338+
expect(scope.$eval(scope.data)).toEqual(undefined);
339+
340+
scope.buildCSV(scope.data).then(function() {
341+
expect(scope.csv).toBe('');
342+
done();
343+
});
344+
scope.$apply();
345+
});
326346
});

0 commit comments

Comments
 (0)