You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by "ASF GitHub Bot (JIRA)" <ji...@apache.org> on 2015/09/18 17:41:04 UTC
[jira] [Commented] (COUCHDB-2818) Design documents accept invalid
views
[ https://issues.apache.org/jira/browse/COUCHDB-2818?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14875799#comment-14875799 ]
ASF GitHub Bot commented on COUCHDB-2818:
-----------------------------------------
GitHub user nickva opened a pull request:
https://github.com/apache/couchdb-couch-mrview/pull/28
Validate design documents.
Jira: COUCHDB-2818
Validates:
* options,filters,lists,shows,updates,views values at
top level of document are objects
* validate_doc_upate,language are strings
* rewrites is an array
* each view inside the views object is an object
* each view object has a map function that is a string
* if a view object has a reduce function it is a string
On validation error it returns a 400 error code with exact
reason what field has failed to validate.
Example:
{code}
http PUT $DB1/db2/_design/des1 views:='{ "m":"bad" }'{"ok":true}
HTTP/1.1 400 Bad Request
{
"error": "invalid_design_doc",
"reason": "View m must be an object"
}
{code}
You can merge this pull request into a Git repository by running:
$ git pull https://github.com/nickva/couchdb-couch-mrview 2818-validate-design-docs
Alternatively you can review and apply these changes as the patch at:
https://github.com/apache/couchdb-couch-mrview/pull/28.patch
To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:
This closes #28
----
commit 629ada826fc712531e7ae826c9b7b1dfe5bafbbb
Author: Nick Vatamaniuc <va...@gmail.com>
Date: 2015-09-18T15:27:39Z
Validate design documents.
Jira: COUCHDB-2818
Validates:
* options,filters,lists,shows,updates,views values at
top level of document are objects
* validate_doc_upate,language are strings
* rewrites is an array
* each view inside the views object is an object
* each view object has a map function that is a string
* if a view object has a reduce function it is a string
On validation error it returns a 400 error code with exact
reason what field has failed to validate.
Example:
{code}
http PUT $DB1/db2/_design/des1 views:='{ "m":"bad" }'{"ok":true}
HTTP/1.1 400 Bad Request
{
"error": "invalid_design_doc",
"reason": "View m must be an object"
}
{code}
----
> Design documents accept invalid views
> -------------------------------------
>
> Key: COUCHDB-2818
> URL: https://issues.apache.org/jira/browse/COUCHDB-2818
> Project: CouchDB
> Issue Type: Bug
> Security Level: public(Regular issues)
> Components: Database Core, Documentation, JavaScript View Server
> Reporter: Nick Vatamaniuc
>
> Design documents seem to accept invalid views.
> For example:
> {code}
> $ 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"
> }
> {code}
> 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:
> {code}
> $ 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."
> }
> {code}
> Also there is a deeper level validation of map functions:
> {code}
> $ http PUT $DB1/db2/_design/des1 views:='{ "m":{"map":""} }'
> {
> "error": "not_found",
> "reason": "missing function"
> }
> {code}
> 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:
> {code}
> $ 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"
> }
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)