serialize and escape quotes on nested objects when exporting as csv

This commit is contained in:
maxogden
2011-03-08 20:16:10 -08:00
parent d54b6a497c
commit f2a10600c0
3 changed files with 6 additions and 4 deletions

View File

@@ -11,8 +11,7 @@
<script type="text/javascript"> <script type="text/javascript">
$(function() { $(function() {
var name, var baseURL = "_rewrite/",
baseURL = "_rewrite/",
vhost = false; vhost = false;
if (document.location.pathname.indexOf("_design") == -1) { if (document.location.pathname.indexOf("_design") == -1) {
@@ -32,6 +31,7 @@
} }
function gotDb(dbInfo) { function gotDb(dbInfo) {
render('db', 'stats', dbInfo); render('db', 'stats', dbInfo);
var data = { var data = {

View File

@@ -18,7 +18,9 @@ function(head, req) {
for (var header in headers) { for (var header in headers) {
if (row.value[headers[header]]) { if (row.value[headers[header]]) {
if (startedOutput) send(","); if (startedOutput) send(",");
send("\"" + row.value[headers[header]] + "\""); var value = row.value[headers[header]];
if (typeof(value) == "object") value = JSON.stringify(value).replace(/"/g, '\\"');
send("\"" + value + "\"");
} else { } else {
if (startedOutput) send(","); if (startedOutput) send(",");
} }

View File

@@ -21,7 +21,7 @@
}, },
{ {
"to": "_list/csv/all", "to": "_list/csv/all",
"from": "*.csv" "from": "csv"
}, },
{ {
"to": "_list/urlencode/headers", "to": "_list/urlencode/headers",