Uploaded image for project: 'CouchDB'
  1. CouchDB
  2. COUCHDB-2818

Design documents accept invalid views

    XMLWordPrintableJSON

Details

    Description

      Design documents seem to accept invalid views.

      For example:

      $ http PUT $DB1/db2/_design/des1 views:='{ "v1" : "function(d){emit(d._id,d);}" }'
      HTTP/1.1 201 Created
      {
          "id": "_design/des1",
          "ok": true,
          "rev": "1-04701f13eb827265c442d219bd995e91"
      }
      

      Going by the documentation for design documents: http://docs.couchdb.org/en/latest/api/ddoc/common.html#put--db-_design-ddoc , a view should be an object that has a map (a string) and an optional reduce (string).

      Interestingly some validation is performed to check that views field itself is an object. For example:

      $ http PUT $DB1/db2/_design/des1 views:='"x"'
      HTTP/1.1 400 Bad Request
      {
          "error": "invalid_design_doc",
          "reason": "`views` parameter must be an object."
      }
      

      Also there is a deeper level validation of map functions:

      $  http PUT $DB1/db2/_design/des1 views:='{ "m":{"map":""} }'
      {
          "error": "not_found",
          "reason": "missing function"
      }
      

      If there is interest, I have a patch that, if provided: views, filters, lists, show, updates, options are objects. rewrites are arrays, validate_doc_update and language are strings.

      Then if views is provided, each view is an object. It must have a map function (a string) and an optional reduce function (also a string).

      Here is an example how it works:

      $ http PUT $DB1/db2/_design/des1 views:='{ "m":"bad"  }'
      HTTP/1.1 400 Bad Request
      {
          "error": "invalid_design_doc",
          "reason": "View m must be an object"
      }
      

      Attachments

        Activity

          People

            kzx kzx
            vatamane Nick Vatamaniuc
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: