From b7c7063f478b0080ef50264df588b5704cc1eeaa Mon Sep 17 00:00:00 2001 From: sambhavjai <38015768+sambhavjai@users.noreply.github.com> Date: Mon, 15 Mar 2021 13:58:22 +0530 Subject: [PATCH 1/3] add file extension based loading --- lib/run/options.js | 57 +++++++++++++++++++--------------------------- 1 file changed, 24 insertions(+), 33 deletions(-) diff --git a/lib/run/options.js b/lib/run/options.js index 7239539fb..df3ff3cf6 100644 --- a/lib/run/options.js +++ b/lib/run/options.js @@ -1,6 +1,6 @@ var _ = require('lodash'), fs = require('fs'), - async = require('async'), + // async = require('async'), Collection = require('postman-collection').Collection, VariableScope = require('postman-collection').VariableScope, CookieJar = require('tough-cookie').CookieJar, @@ -271,39 +271,30 @@ var _ = require('lodash'), if (err) { return callback(new Error(ITERATION_DATA_LOAD_ERROR_MESSAGE + `\n ${err.message || err}`)); } - - // Try loading as a JSON, fall-back to CSV. @todo: switch to file extension based loading. - async.waterfall([ - (cb) => { - try { - return cb(null, liquidJSON.parse(data.trim())); - } - catch (e) { - return cb(null, undefined); // e masked to avoid displaying JSON parse errors for CSV files + // parse the data according to the file extension + try { // check the file extension using the file location + if (location.split(/[#?]/)[0].split('.').pop().trim() === 'json') { + return callback(null, liquidJSON.parse(data.trim())); + } // if file extension is not json then parse csv + parseCsv(data, { + columns: true, // infer the columns names from the first row + escape: '"', // escape character + cast: csvAutoParse, // function to cast values of individual fields + trim: true, // ignore whitespace immediately around the delimiter + relax: true, // allow using quotes without escaping inside unquoted string + relax_column_count: true, // ignore inconsistent columns count + bom: true // strip the byte order mark (BOM) from the input string + }, (err, parsedData) => { + if (err || !parsedData) { + return callback(new Error(ITERATION_DATA_LOAD_ERROR_MESSAGE + `\n ${err.message || err}`)); } - }, - (json, cb) => { - if (json) { - return cb(null, json); - } - // Wasn't JSON - parseCsv(data, { - columns: true, // infer the columns names from the first row - escape: '"', // escape character - cast: csvAutoParse, // function to cast values of individual fields - trim: true, // ignore whitespace immediately around the delimiter - relax: true, // allow using quotes without escaping inside unquoted string - relax_column_count: true, // ignore inconsistent columns count - bom: true // strip the byte order mark (BOM) from the input string - }, cb); - } - ], (err, parsed) => { - if (err) { - return callback(new Error(ITERATION_DATA_LOAD_ERROR_MESSAGE + `\n ${err.message || err}`)); - } - - callback(null, parsed); - }); + + return callback(null, parsedData); + }); + } + catch (e) { + return callback(new Error(ITERATION_DATA_LOAD_ERROR_MESSAGE + `\n ${e}`)); + } }); }, From 808e9ba3436e72173a25727e96fc0ee187acd32a Mon Sep 17 00:00:00 2001 From: sambhavjai <38015768+sambhavjai@users.noreply.github.com> Date: Wed, 17 Mar 2021 16:11:36 +0530 Subject: [PATCH 2/3] Revert "add file extension based loading" --- lib/run/options.js | 57 +++++++++++++++++++++++++++------------------- 1 file changed, 33 insertions(+), 24 deletions(-) diff --git a/lib/run/options.js b/lib/run/options.js index df3ff3cf6..7239539fb 100644 --- a/lib/run/options.js +++ b/lib/run/options.js @@ -1,6 +1,6 @@ var _ = require('lodash'), fs = require('fs'), - // async = require('async'), + async = require('async'), Collection = require('postman-collection').Collection, VariableScope = require('postman-collection').VariableScope, CookieJar = require('tough-cookie').CookieJar, @@ -271,30 +271,39 @@ var _ = require('lodash'), if (err) { return callback(new Error(ITERATION_DATA_LOAD_ERROR_MESSAGE + `\n ${err.message || err}`)); } - // parse the data according to the file extension - try { // check the file extension using the file location - if (location.split(/[#?]/)[0].split('.').pop().trim() === 'json') { - return callback(null, liquidJSON.parse(data.trim())); - } // if file extension is not json then parse csv - parseCsv(data, { - columns: true, // infer the columns names from the first row - escape: '"', // escape character - cast: csvAutoParse, // function to cast values of individual fields - trim: true, // ignore whitespace immediately around the delimiter - relax: true, // allow using quotes without escaping inside unquoted string - relax_column_count: true, // ignore inconsistent columns count - bom: true // strip the byte order mark (BOM) from the input string - }, (err, parsedData) => { - if (err || !parsedData) { - return callback(new Error(ITERATION_DATA_LOAD_ERROR_MESSAGE + `\n ${err.message || err}`)); - } - return callback(null, parsedData); - }); - } - catch (e) { - return callback(new Error(ITERATION_DATA_LOAD_ERROR_MESSAGE + `\n ${e}`)); - } + // Try loading as a JSON, fall-back to CSV. @todo: switch to file extension based loading. + async.waterfall([ + (cb) => { + try { + return cb(null, liquidJSON.parse(data.trim())); + } + catch (e) { + return cb(null, undefined); // e masked to avoid displaying JSON parse errors for CSV files + } + }, + (json, cb) => { + if (json) { + return cb(null, json); + } + // Wasn't JSON + parseCsv(data, { + columns: true, // infer the columns names from the first row + escape: '"', // escape character + cast: csvAutoParse, // function to cast values of individual fields + trim: true, // ignore whitespace immediately around the delimiter + relax: true, // allow using quotes without escaping inside unquoted string + relax_column_count: true, // ignore inconsistent columns count + bom: true // strip the byte order mark (BOM) from the input string + }, cb); + } + ], (err, parsed) => { + if (err) { + return callback(new Error(ITERATION_DATA_LOAD_ERROR_MESSAGE + `\n ${err.message || err}`)); + } + + callback(null, parsed); + }); }); }, From e58e2eac8b7805feac6e91055cd311f678094318 Mon Sep 17 00:00:00 2001 From: sambhavjai <38015768+sambhavjai@users.noreply.github.com> Date: Wed, 17 Mar 2021 16:21:59 +0530 Subject: [PATCH 3/3] remove todo file extension based loading --- lib/run/options.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/run/options.js b/lib/run/options.js index 7239539fb..0f4fe4299 100644 --- a/lib/run/options.js +++ b/lib/run/options.js @@ -272,7 +272,7 @@ var _ = require('lodash'), return callback(new Error(ITERATION_DATA_LOAD_ERROR_MESSAGE + `\n ${err.message || err}`)); } - // Try loading as a JSON, fall-back to CSV. @todo: switch to file extension based loading. + // Try loading as a JSON, fall-back to CSV. async.waterfall([ (cb) => { try {