Skip to content

Commit 4fdf348

Browse files
committed
Adds support for spaces in options.
1 parent 617f371 commit 4fdf348

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

src/https/Program.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,6 +376,17 @@ public static IEnumerable<string> GetOptionHelp()
376376
yield return "--xml <ROOT_NAME> Renders the content arguments as application/xml using the optional xml root name.";
377377
}
378378

379+
static int GetArgValueIndex(string arg)
380+
{
381+
var equalsIndex = arg.IndexOf('=');
382+
var spaceIndex = arg.IndexOf(' ');
383+
var index = equalsIndex > -1 && spaceIndex > -1
384+
? Math.Min(equalsIndex, spaceIndex)
385+
: Math.Max(equalsIndex, spaceIndex);
386+
387+
return index == -1 ? index : index + 1;
388+
}
389+
379390
public static Options Parse(IEnumerable<string> args)
380391
{
381392
var requestContentType = ContentType.Json;
@@ -392,14 +403,14 @@ public static Options Parse(IEnumerable<string> args)
392403
}
393404
else if (arg.StartsWith("--xml"))
394405
{
395-
var index = arg.IndexOf('=');
406+
var index = GetArgValueIndex(arg);
396407
if (index == -1)
397408
{
398409
xmlRootName = "xml";
399410
}
400411
else
401412
{
402-
xmlRootName = arg.Substring(index + 1).Trim();
413+
xmlRootName = arg.Substring(index).Trim();
403414
if (string.IsNullOrEmpty(xmlRootName))
404415
{
405416
xmlRootName = "xml";
@@ -417,10 +428,10 @@ public static Options Parse(IEnumerable<string> args)
417428
}
418429
else if (arg.StartsWith("--timeout"))
419430
{
420-
var index = arg.IndexOf('=');
431+
var index = GetArgValueIndex(arg);
421432
if (index > -1)
422433
{
423-
var s = arg.Substring(index + 1).Trim();
434+
var s = arg.Substring(index).Trim();
424435
if (TimeSpan.TryParse(s, out var to) && to > TimeSpan.Zero)
425436
{
426437
timeout = to;

0 commit comments

Comments
 (0)