summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorJohn Christopher Anderson <jchris@apache.org>2009-12-06 22:47:05 +0000
committerJohn Christopher Anderson <jchris@apache.org>2009-12-06 22:47:05 +0000
commitf94630fd4af5656b4412ca5de0fc1211d19ddbf3 (patch)
tree998a65ca87e0cb3afa279d48e5466e05fa9c5a49 /share
parent60a6b3e7ffa209da31d563beae33726412318957 (diff)
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
Diffstat (limited to 'share')
-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");