Skip to content

Commit

Permalink
Use CSV stringify to properly escape data in CSV
Browse files Browse the repository at this point in the history
  • Loading branch information
TheMarex authored and Patrick Niklaus committed Apr 17, 2018
1 parent 4654751 commit 29db0c8
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
"chalk": "^1.1.3",
"command-line-args": "^5.0.2",
"command-line-usage": "^5.0.4",
"csv-stringify": "^3.0.0",
"cucumber": "^1.2.1",
"d3-queue": "^2.0.3",
"docbox": "^1.0.6",
Expand Down
10 changes: 4 additions & 6 deletions scripts/osrm-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ const clu = require('command-line-usage');
const ansi = require('ansi-escape-sequences');
const turf = require('turf');
const jp = require('jsonpath');
const csv_stringify = require('csv-stringify/lib/sync');

const run_query = (query_options, filters, callback) => {
let tic = () => 0.;
Expand Down Expand Up @@ -123,11 +124,8 @@ queries = queries.map(q => { return {hostname: options.server.hostname, port: op
http.globalAgent.maxSockets = options['max-sockets'];
queries.map(query => {
run_query(query, options.filter, (query, code, ttfb, total, results) => {
let str = `"${query}",${code}`;
if (ttfb !== undefined) str += `,${ttfb}`;
if (total !== undefined) str += `,${total}`;
if (typeof results === 'object' && results.length > 0)
str += ',' + results.map(x => isNaN(x) ? '"' + JSON.stringify(x).replace(/\n/g, ';').replace(/"/g, "'") + '"' : Number(x)).join(',');
console.log(str);
let data = results ? JSON.stringify(results[0]) : '';
let record = [[query, code, ttfb, total, data]];
process.stdout.write(csv_stringify(record));
});
});

0 comments on commit 29db0c8

Please sign in to comment.