From f94630fd4af5656b4412ca5de0fc1211d19ddbf3 Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Sun, 6 Dec 2009 22:47:05 +0000 Subject: fix COUCHDB-593, thanks Roger Binns for reporting git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@887791 13f79535-47bb-0310-9956-ffa450edef68 --- share/server/render.js | 20 ++++++++++++++++++-- share/www/script/test/show_documents.js | 7 +++++++ 2 files changed, 25 insertions(+), 2 deletions(-) (limited to 'share') diff --git a/share/server/render.js b/share/server/render.js index 82ceb3ab..f147af89 100644 --- a/share/server/render.js +++ b/share/server/render.js @@ -197,6 +197,21 @@ function resetProvides() { responseContentType = null; }; +// from http://javascript.crockford.com/remedial.html +function typeOf(value) { + var s = typeof value; + if (s === 'object') { + if (value) { + if (value instanceof Array) { + s = 'array'; + } + } else { + s = 'null'; + } + } + return s; +}; + function runShow(showFun, doc, req, funSrc) { try { resetProvides(); @@ -206,8 +221,9 @@ function runShow(showFun, doc, req, funSrc) { resp = runProvides(req); resp = applyContentType(maybeWrapResponse(resp), responseContentType); } - - if (resp) { + + var type = typeOf(resp); + if (type == 'object' || type == 'string') { respond(["resp", maybeWrapResponse(resp)]); } else { renderError("undefined response from show function"); diff --git a/share/www/script/test/show_documents.js b/share/www/script/test/show_documents.js index d0a2325a..ae4368a8 100644 --- a/share/www/script/test/show_documents.js +++ b/share/www/script/test/show_documents.js @@ -56,6 +56,9 @@ couchTests.show_documents = function(debug) { "render-error" : stringFun(function(doc, req) { return noSuchVariable; }), + "empty" : stringFun(function(doc, req) { + return ""; + }), "xml-type" : stringFun(function(doc, req) { return { "headers" : { @@ -159,6 +162,10 @@ couchTests.show_documents = function(debug) { xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/hello"); T(xhr.responseText == "Empty World"); + // hello template world (no docid) + xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/empty"); + T(xhr.responseText == ""); + // // hello template world (non-existing docid) xhr = CouchDB.request("GET", "/test_suite_db/_design/template/_show/hello/nonExistingDoc"); T(xhr.responseText == "New World"); -- cgit v1.2.3