summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--share/server/render.js20
-rw-r--r--share/www/script/test/show_documents.js7
2 files changed, 25 insertions, 2 deletions
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");