You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by jc...@apache.org on 2009/12/06 23:47:06 UTC

svn commit: r887791 - in /couchdb/trunk/share: server/render.js www/script/test/show_documents.js

Author: jchris
Date: Sun Dec  6 22:47:05 2009
New Revision: 887791

URL: http://svn.apache.org/viewvc?rev=887791&view=rev
Log:
fix COUCHDB-593, thanks Roger Binns for reporting

Modified:
    couchdb/trunk/share/server/render.js
    couchdb/trunk/share/www/script/test/show_documents.js

Modified: couchdb/trunk/share/server/render.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/server/render.js?rev=887791&r1=887790&r2=887791&view=diff
==============================================================================
--- couchdb/trunk/share/server/render.js (original)
+++ couchdb/trunk/share/server/render.js Sun Dec  6 22:47:05 2009
@@ -197,6 +197,21 @@
   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 @@
       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");

Modified: couchdb/trunk/share/www/script/test/show_documents.js
URL: http://svn.apache.org/viewvc/couchdb/trunk/share/www/script/test/show_documents.js?rev=887791&r1=887790&r2=887791&view=diff
==============================================================================
--- couchdb/trunk/share/www/script/test/show_documents.js (original)
+++ couchdb/trunk/share/www/script/test/show_documents.js Sun Dec  6 22:47:05 2009
@@ -56,6 +56,9 @@
       "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 @@
   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");