From eaaae6d2a99f00e15d8f5c588a47d439bc3c833a Mon Sep 17 00:00:00 2001 From: Mark van Renswoude Date: Mon, 6 Sep 2021 13:32:55 +0200 Subject: [PATCH] Tapeti.Cmd: support for url-encoded messages on the command line --- Tapeti.Cmd/Verbs/ImportVerb.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Tapeti.Cmd/Verbs/ImportVerb.cs b/Tapeti.Cmd/Verbs/ImportVerb.cs index cb2eb73..9b4ce3a 100644 --- a/Tapeti.Cmd/Verbs/ImportVerb.cs +++ b/Tapeti.Cmd/Verbs/ImportVerb.cs @@ -1,5 +1,6 @@ -using System; +using System; using System.IO; +using System.Net; using System.Text; using CommandLine; using RabbitMQ.Client; @@ -18,9 +19,12 @@ namespace Tapeti.Cmd.Verbs [Option('m', "message", Group = "Input", HelpText = "Single message to be sent, in the same format as used for SingleFileJSON. Serialization argument has no effect when using this input.")] public string InputMessage { get; set; } - + [Option('c', "pipe", Group = "Input", HelpText = "Messages are read from the standard input pipe, in the same format as used for SingleFileJSON. Serialization argument has no effect when using this input.")] public bool InputPipe { get; set; } + + [Option("urlencoded", HelpText = "Indicates the message is URL encoded. Only applies to messages passed directly with --message as quotes are very quirky on the command-line, even more so in PowerShell.")] + public bool UrlEncoded { get; set; } [Option('e', "exchange", HelpText = "If specified publishes to the originating exchange using the original routing key. By default these are ignored and the message is published directly to the originating queue.")] public bool PublishToExchange { get; set; } @@ -133,8 +137,12 @@ namespace Tapeti.Cmd.Verbs if (!string.IsNullOrEmpty(options.InputMessage)) { + var inputMessage = options.UrlEncoded + ? WebUtility.UrlDecode(options.InputMessage) + : options.InputMessage; + disposeStream = true; - return new MemoryStream(Encoding.UTF8.GetBytes(options.InputMessage)); + return new MemoryStream(Encoding.UTF8.GetBytes(inputMessage)); } disposeStream = true;