Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

# character causes fail in FireFox #41

Closed
petecleary opened this issue Jul 11, 2014 · 9 comments
Closed

# character causes fail in FireFox #41

petecleary opened this issue Jul 11, 2014 · 9 comments

Comments

@petecleary
Copy link

The rendering of the csv content stops in FireFox when the code first encounters a # character.

Only tested in FireFox 30 to date.

See the issue @ http://jsfiddle.net/z3bs2/

Pete

@petecleary
Copy link
Author

Hi

I have done some more investigation and it appears to be because your are encoding using encodeURI which will omit encoding URL characters , / ? : @ & = + $ #

By changing the encoding to the field item and encoding it fully then it renders correctly within FireFox, this only works with the text delimiter set.

Below is my reworked buildCSV function.

$scope.buildCsv = function () {
            var data = $scope.data();
            var csvContent = 'data:text/csv;charset=utf-8,';

            // Check if there's a provided header array
            var header = $scope.header();
            if (header) {
              var encodingArray = [];
              angular.forEach(header, function (title) {
                this.push(title);
              }, encodingArray);

              var headerString = encodingArray.join($scope.fieldSep || ',');
              //csvContent += headerString + '\r\n'; *** REPLACE WITH THE ENCODED LINE ENDINGS
              csvContent += headerString + '%0D%0A';
            }

            // Process the data
            angular.forEach(data, function (row, index) {
              var infoArray = [];
              angular.forEach(row, function (field) {
                if (typeof field === 'string' && $scope.txtDelim) {
                    //field = $scope.txtDelim + field + $scope.txtDelim; *** REPLACE WITH ENCODING THE FIELD VALUE
                    field = $scope.txtDelim + encodeURIComponent(field) + $scope.txtDelim;
                }
                this.push(field);
              }, infoArray);
              dataString = infoArray.join($scope.fieldSep || ',');
              //csvContent += index < data.length ? dataString + '\r\n' : dataString; *** REPLACE WITH THE ENCODED LINE ENDINGS
              csvContent += index < data.length ? dataString + '%0D%0A' : dataString;
            });

            //$scope.csv = encodeURI(csvContent); *** REPLACE WITH NOT ENCODING AS IT IS DONE ABOVE
            $scope.csv = csvContent;
            return $scope.csv;
          };

Pete

@asafdav
Copy link
Owner

asafdav commented Jul 13, 2014

Hi,
Can you please send a pull request ?
It would be much easier to go over your code.

Thanks again!

@petecleary
Copy link
Author

Hi

I've forked your code and it has changed from the version I re-wrote locally. I will need some time to check your current version and change accordingly.

Pete

@asafdav
Copy link
Owner

asafdav commented Jul 15, 2014

What ng-csv version did you started with ?

On Tue, Jul 15, 2014 at 10:14 AM, Pete Cleary notifications@github.com
wrote:

Hi

I've forked your code and it has changed from the version I re-wrote
locally. I will need some time to check your current version and change
accordingly.

Pete


Reply to this email directly or view it on GitHub
#41 (comment).

@petecleary
Copy link
Author

Good question, I built the initial system back in Feb, so it looks like the version compiled from Jan
https://github.com/asafdav/ng-csv/blob/1e29fcb45f7404499d71acd85a331f997fecd75c/build/ng-csv.js

@petecleary
Copy link
Author

My JS Fiddle with the new code still fails in FF.
http://jsfiddle.net/z3bs2/

@asafdav
Copy link
Owner

asafdav commented Jul 15, 2014

Ok I'll take a look, thanks!
On Jul 15, 2014 10:44 AM, "Pete Cleary" notifications@github.com wrote:

My JS Fiddle with the new code still fails in FF.
http://jsfiddle.net/z3bs2/


Reply to this email directly or view it on GitHub
#41 (comment).

@asafdav
Copy link
Owner

asafdav commented Jul 16, 2014

Hi, Thanks for the fiddle,
I went through it, you didn't use the latest version of ngCsv but the issue persisted in the newest version as well, I just pushed a fix.

Checkout the updated fiddle, http://jsfiddle.net/utCt3/
It seems like working now.

Thanks again for your help, I hope you can switch back to the main branch.

@asafdav asafdav closed this as completed Jul 16, 2014
@petecleary
Copy link
Author

Thank you, it is working well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants