horta-hell
horta-hell copied to clipboard
Add support for quoted command arguments
We should add support for the following syntax:
$send xxx "aaa bbb ccc"
(parse spaces inside quotes as part of argument)
I worked on the command parsers when Horta was a baby. So I can take this issue.
What about string escaping? Maybe we should use or """ """ ? =)
I think it would be enough to improve send and replace:
override def processCommand(credential: Credential,
token: Any,
arguments: Array[String]) {
token match {
case SendMailCommand =>
arguments match {
case Array(receiver, message) if receiver.nonEmpty => sendMail(credential, receiver, message)
case _ => Protocol.sendResponse(
credential.location,
credential,
Localization.localize("Invalid arguments.")(credential))
}
case _ =>
}
}
by something like:
override def processCommand(credential: Credential,
token: Any,
arguments: Array[String]) {
token match {
case SendMailCommand =>
arguments match {
case Array(receiver, messageParts@_*) if receiver.nonEmpty => sendMail(credential, receiver, messageParts.mkString(" "))
case _ => Protocol.sendResponse(
credential.location,
credential,
Localization.localize("Invalid arguments.")(credential))
}
case _ =>
}
}
@ttldtor why did you decompress a PR patch into a comment?
@ttldtor while filing this proposal I meant that the new quoting syntax should be supported for every command and not just Mail plugin (because people often want to send long arguments to e.g. pet change-nick or search commands). That's not the right solution to match any "additional" arguments in any command processor, and we're going to remove these matchers instead of making more of them (because matching any additional arguments often leads to security exploits).
I fear that we can fall into the same situation as shell command line tokenizer (the one that parses command arguments and passes them into argc / argv): it first decomposes the command line into tokens, and then many applications are trying to concatenate them back (while losing formatting, opening and closing quotes, escaping etc.). We're not going that way.
What I thought that we need to use real escaping inside of the "quoted \"string\"", but your proposals about using double quotes as an escape sequence or providing an alternate quote character ``` are also viable, thank you.
@rexim lazy lazy val pr = ...
@ttldtor why did you decompress a PR patch into a comment?
@ForNeVeR thanks for the explanation.