Comparing version 3.0.0 to 3.0.1
@@ -89,3 +89,3 @@ 'use strict'; | ||
if (!(Array.isArray(dataset)) && !(dataset === Object(dataset))) { | ||
return dataset; | ||
return internals.escapeQuotesInString(dataset); | ||
} | ||
@@ -205,3 +205,3 @@ | ||
if (!(Array.isArray(dataset))) { | ||
if (!Array.isArray(dataset)) { | ||
dataset = [dataset]; | ||
@@ -234,3 +234,3 @@ } | ||
else { | ||
dataRow += `"${temp}"`; | ||
dataRow += `"${internals.escapeQuotesInString(temp)}"`; | ||
} | ||
@@ -246,1 +246,10 @@ | ||
}; | ||
internals.escapeQuotesInString = (str) => { | ||
if (typeof str === 'string' || str instanceof String) { | ||
return str.replace(/"/g, '""'); | ||
} | ||
return str; | ||
}; |
@@ -0,0 +0,0 @@ The MIT License (MIT) |
{ | ||
"name": "hapi-csv", | ||
"version": "3.0.0", | ||
"version": "3.0.1", | ||
"description": "Hapi plugin for converting a Joi response schema and dataset to csv", | ||
@@ -30,3 +30,3 @@ "main": "lib/index.js", | ||
"hapi": "16.x.x", | ||
"lab": "11.x.x" | ||
"lab": "12.x.x" | ||
}, | ||
@@ -33,0 +33,0 @@ "peerDependencies": { |
@@ -0,0 +0,0 @@ # Hapi-csv [![Build Status](https://travis-ci.org/Salesflare/hapi-csv.svg?branch=master)](https://travis-ci.org/Salesflare/hapi-csv) |
@@ -44,3 +44,3 @@ 'use strict'; | ||
}; | ||
const userCSV = `first_name,last_name,age,\n"firstName","lastName","25",`; | ||
const userCSV = 'first_name,last_name,age,\n"firstName","lastName","25",'; | ||
const testResponseSchema = Joi.object().keys({ | ||
@@ -401,2 +401,47 @@ first_name: Joi.string(), | ||
}); | ||
it('Parse a value containing embedded double quotes', (done) => { | ||
const server = new Hapi.Server(); | ||
server.connection(); | ||
return server.register(HapiCsv, (err) => { | ||
expect(err, 'error').to.not.exist(); | ||
server.route([{ | ||
method: 'GET', | ||
path: '/test', | ||
config: { | ||
handler: function (request, reply) { | ||
return reply('I said: "Hello"'); | ||
}, | ||
response: { | ||
schema: Joi.string() | ||
} | ||
} | ||
}]); | ||
return server.initialize((err) => { | ||
expect(err, 'error').to.not.exist(); | ||
return server.inject({ | ||
method: 'GET', | ||
url: '/test', | ||
headers: { | ||
'Accept': 'text/csv' | ||
} | ||
}, (res) => { | ||
expect(res.result).to.equal('I said: ""Hello""'); | ||
expect(res.headers['content-type']).to.equal('text/csv; charset=utf-8'); | ||
expect(res.headers['content-disposition']).to.equal('attachment;'); | ||
return server.stop(done); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); | ||
@@ -415,3 +460,3 @@ | ||
}; | ||
const userCSV = `first_name+last_name+age+tags_0+\n"firstName"+"lastName"+"25"+"person"+`; | ||
const userCSV = 'first_name+last_name+age+tags_0+\n"firstName"+"lastName"+"25"+"person"+'; | ||
@@ -490,3 +535,3 @@ const server = new Hapi.Server(); | ||
const userCSV = `first_name,last_name,age,\n"firstName1","lastName1","25",\n"firstName2","lastName2","27",`; | ||
const userCSV = 'first_name,last_name,age,\n"firstName1","lastName1","25",\n"firstName2","lastName2","27",'; | ||
@@ -562,3 +607,3 @@ const server = new Hapi.Server(); | ||
const userCSV = `first_name,last_name,age,\n"firstName1","lastName1","25",\n"firstName2","lastName2","27",`; | ||
const userCSV = 'first_name,last_name,age,\n"firstName1","lastName1","25",\n"firstName2","lastName2","27",'; | ||
@@ -565,0 +610,0 @@ const server = new Hapi.Server(); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
34151
698