Karthikeya1500 commented on PR #5941:
URL: https://github.com/apache/couchdb/pull/5941#issuecomment-4125697831
Hi @janl, thanks for taking a look!
I considered just replacing cmdkey with cmd in the default case instead of
declaring the variable, but there is a catch: because cmd is an array created
from JSON.parse(line), evaluating switch(cmd.shift()) removes the command name
string from the array.
If we use cmd in the error string later, it will print whatever arguments
remain in the array rather than the command name itself. For example, if an
unknown command payload of ["unknown_cmd", "arg1"] is sent, cmd.shift() leaves
cmd as ["arg1"], meaning the error would incorrectly print out unknown command
'arg1'.
I also noticed that the SpiderMonkey dispatcher in
share/server/loop.js
explicitly captures cmdkey = cmd.shift(); before evaluating for this exact
reason, so my fix essentially copies that working pattern into the QuickJS
dispatcher.
Let me know if that makes sense or if you prefer a different approach!
--
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]