jcoglan commented on code in PR #5858:
URL: https://github.com/apache/couchdb/pull/5858#discussion_r3333001034
##########
src/mango/src/mango_native_proc.erl:
##########
@@ -112,14 +112,30 @@ handle_call({prompt, [<<"ddoc">>, DDocId,
[<<"validate_doc_update">>], Args]}, _
Msg = [<<"validate_doc_update">>, DDocId],
{stop, {invalid_call, Msg}, {invalid_call, Msg}, St};
Selector ->
- [NewDoc, OldDoc, _Ctx, _SecObj] = Args,
- Struct = {[{<<"newDoc">>, NewDoc}, {<<"oldDoc">>, OldDoc}]},
- Reply =
- case mango_selector:match(Selector, Struct) of
- true -> true;
- _ -> {[{<<"forbidden">>, <<"document is not valid">>}]}
- end,
- {reply, Reply, St}
+ case mango_selector:has_allowed_fields(Selector, [<<"newDoc">>,
<<"oldDoc">>]) of
+ false ->
+ Msg =
+ <<"'validate_doc_update' may only contain 'newDoc' and
'oldDoc' as top-level fields">>,
Review Comment:
Actually I wasn't quite right. `map` functions are checked when the ddoc is
updated, but `validate_doc_update` is not. The compilation error is surfaced
when other docs are written and we attempt to invoke the VDU function.
```sh
$ cdb '/asd/_design/foo' -X PUT -d '{ "validate_doc_update": "function (doc)
{" }'
{"ok":true,"id":"_design/foo","rev":"1-416ed8128d308d5abc6b4745a64394e5"}
$ cdb '/asd/doc' -X PUT -d '{}'
{"error":"compilation_error","reason":"SyntaxError: unexpected token in
expression: '' (function (doc) {)"}
```
Personally I think this behaviour should be consistent between JS and Mango
VDUs, and if we want to preemptively validate the v-d-u field we should do this
for both backends.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]