properly escape csv headers

This commit is contained in:
maxogden 2011-04-29 16:27:45 -07:00
parent c2131051ff
commit def8bbefd0
2 changed files with 5 additions and 3 deletions

View File

@ -9,11 +9,11 @@
*/
function(head, req) {
if ('headers' in req.query) {
var headers = eval(unescape(req.query.headers.split(',')));
var headers = JSON.parse(unescape(req.query.headers))[0];
var row, sep = '\n', headerSent = false, startedOutput = false;
start({"headers":{"Content-Type" : "text/x-csv"}});
send(headers.join(',') + "\n");
send('"' + headers.join('","') + '"\n');
while (row = getRow()) {
for (var header in headers) {
if (row.value[headers[header]]) {

View File

@ -12,9 +12,11 @@ function(head, req) {
if ('callback' in req.query) send(req.query['callback'] + "(");
var rows = []
while (row = getRow()) {
send(escape(JSON.stringify(row.value)));
rows.push(row.value)
}
send(escape(JSON.stringify(rows)));
if ('callback' in req.query) send(")");
};