diff --git a/share/server/dispatch-quickjs.js b/share/server/dispatch-quickjs.js index 5f69f6188ac..2f05118b313 100644 --- a/share/server/dispatch-quickjs.js +++ b/share/server/dispatch-quickjs.js @@ -154,7 +154,8 @@ globalThis.dispatch = function(line) { const cmd = JSON.parse(line); State.line_length = line.length; try { - switch (cmd.shift()) { + const cmdkey = cmd.shift(); + switch (cmdkey) { case "ddoc": DDoc.ddoc.apply(null, cmd); break; diff --git a/src/couch/test/eunit/couch_js_tests.erl b/src/couch/test/eunit/couch_js_tests.erl index 29b303ffb5f..c5ad53eaaaf 100644 --- a/src/couch/test/eunit/couch_js_tests.erl +++ b/src/couch/test/eunit/couch_js_tests.erl @@ -38,7 +38,8 @@ couch_js_test_() -> ?TDEF(should_allow_js_string_mutations), ?TDEF(should_bump_timing_and_call_stats), ?TDEF(should_exit_on_internal_error, 60), - ?TDEF(should_use_bigint) + ?TDEF(should_use_bigint), + ?TDEF(should_handle_invalid_command) ]) } }. @@ -465,6 +466,11 @@ should_use_bigint(_) -> ?assertThrow({compilation_error, _}, prompt(Proc, [<<"add_fun">>, Src])) end. +should_handle_invalid_command(_) -> + Proc = couch_query_servers:get_os_process(<<"javascript">>), + BadCmd = [<<"bad">>, <<"foo">>], + ?assertThrow({unknown_command, <<"unknown command 'bad'">>}, prompt(Proc, BadCmd)). + sample_time(Stat) -> couch_stats:sample([couchdb, query_server, time, Stat]).