Skip to content

Commit e37cb9b

Browse files
committed
Update PolyfillTests_ProcessStartInfo.cs
1 parent f67064d commit e37cb9b

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed

src/Tests/PolyfillTests_ProcessStartInfo.cs

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -450,5 +450,167 @@ public async Task SyncArgumentWithBackslashesThenQuote()
450450
await Assert.That(info.Arguments).IsEqualTo("\"a\\\\\\\\\\\"b\"");
451451
}
452452

453+
[Test]
454+
public async Task SyncArgumentWithOnlySpaces()
455+
{
456+
var info = new ProcessStartInfo();
457+
var list = new Polyfill.SyncingArgumentList(info);
458+
list.Add(" ");
459+
list.Sync();
460+
461+
await Assert.That(info.Arguments).IsEqualTo("\" \"");
462+
}
463+
464+
[Test]
465+
public async Task SyncArgumentWithLeadingSpace()
466+
{
467+
var info = new ProcessStartInfo();
468+
var list = new Polyfill.SyncingArgumentList(info);
469+
list.Add(" leading");
470+
list.Sync();
471+
472+
await Assert.That(info.Arguments).IsEqualTo("\" leading\"");
473+
}
474+
475+
[Test]
476+
public async Task SyncArgumentWithTrailingSpace()
477+
{
478+
var info = new ProcessStartInfo();
479+
var list = new Polyfill.SyncingArgumentList(info);
480+
list.Add("trailing ");
481+
list.Sync();
482+
483+
await Assert.That(info.Arguments).IsEqualTo("\"trailing \"");
484+
}
485+
486+
[Test]
487+
public async Task SyncArgumentWithMultipleQuotes()
488+
{
489+
var info = new ProcessStartInfo();
490+
var list = new Polyfill.SyncingArgumentList(info);
491+
list.Add("\"\"\"");
492+
list.Sync();
493+
494+
await Assert.That(info.Arguments).IsEqualTo("\"\\\"\\\"\\\"\"");
495+
}
496+
497+
[Test]
498+
public async Task SyncArgumentStartingWithQuote()
499+
{
500+
var info = new ProcessStartInfo();
501+
var list = new Polyfill.SyncingArgumentList(info);
502+
list.Add("\"hello");
503+
list.Sync();
504+
505+
await Assert.That(info.Arguments).IsEqualTo("\"\\\"hello\"");
506+
}
507+
508+
[Test]
509+
public async Task SyncArgumentEndingWithQuote()
510+
{
511+
var info = new ProcessStartInfo();
512+
var list = new Polyfill.SyncingArgumentList(info);
513+
list.Add("hello\"");
514+
list.Sync();
515+
516+
await Assert.That(info.Arguments).IsEqualTo("\"hello\\\"\"");
517+
}
518+
519+
[Test]
520+
public async Task SyncArgumentWithSpacesAndQuotes()
521+
{
522+
var info = new ProcessStartInfo();
523+
var list = new Polyfill.SyncingArgumentList(info);
524+
list.Add("she said \"hi there\"");
525+
list.Sync();
526+
527+
await Assert.That(info.Arguments).IsEqualTo("\"she said \\\"hi there\\\"\"");
528+
}
529+
530+
[Test]
531+
public async Task SyncArgumentWithNewline()
532+
{
533+
var info = new ProcessStartInfo();
534+
var list = new Polyfill.SyncingArgumentList(info);
535+
list.Add("line1\nline2");
536+
list.Sync();
537+
538+
// Newline is whitespace, so the argument gets quoted
539+
await Assert.That(info.Arguments).IsEqualTo("\"line1\nline2\"");
540+
}
541+
542+
[Test]
543+
public async Task SyncArgumentWithSingleQuotes()
544+
{
545+
var info = new ProcessStartInfo();
546+
var list = new Polyfill.SyncingArgumentList(info);
547+
list.Add("it's");
548+
list.Sync();
549+
550+
// Single quotes don't trigger quoting or escaping
551+
await Assert.That(info.Arguments).IsEqualTo("it's");
552+
}
553+
554+
[Test]
555+
public async Task SyncArgumentKeyValueWithSpaces()
556+
{
557+
var info = new ProcessStartInfo();
558+
var list = new Polyfill.SyncingArgumentList(info);
559+
list.Add("--path=C:\\Program Files\\app");
560+
list.Sync();
561+
562+
await Assert.That(info.Arguments).IsEqualTo("\"--path=C:\\Program Files\\app\"");
563+
}
564+
565+
[Test]
566+
public async Task SyncArgumentWithBackslashQuoteBackslash()
567+
{
568+
var info = new ProcessStartInfo();
569+
var list = new Polyfill.SyncingArgumentList(info);
570+
list.Add("a\\\"\\b");
571+
list.Sync();
572+
573+
// backslash before quote is doubled+1, backslash not before quote is kept
574+
await Assert.That(info.Arguments).IsEqualTo("\"a\\\\\\\"\\b\"");
575+
}
576+
577+
[Test]
578+
public async Task SyncMultipleArgumentsWithQuotesAndSpaces()
579+
{
580+
var info = new ProcessStartInfo();
581+
var list = new Polyfill.SyncingArgumentList(info);
582+
list.Add("--name");
583+
list.Add("John \"Johnny\" Doe");
584+
list.Add("--path");
585+
list.Add("C:\\My Documents\\file.txt");
586+
list.Sync();
587+
588+
await Assert.That(info.Arguments).IsEqualTo(
589+
"--name \"John \\\"Johnny\\\" Doe\" --path \"C:\\My Documents\\file.txt\"");
590+
}
591+
592+
[Test]
593+
public async Task SyncArgumentThatIsJustBackslash()
594+
{
595+
var info = new ProcessStartInfo();
596+
var list = new Polyfill.SyncingArgumentList(info);
597+
list.Add("\\");
598+
list.Sync();
599+
600+
// Single backslash, no quotes or spaces, passed through as-is
601+
await Assert.That(info.Arguments).IsEqualTo("\\");
602+
}
603+
604+
[Test]
605+
public async Task SyncArgumentWithConsecutiveSpaces()
606+
{
607+
var info = new ProcessStartInfo();
608+
var list = new Polyfill.SyncingArgumentList(info);
609+
list.Add("a b");
610+
list.Sync();
611+
612+
await Assert.That(info.Arguments).IsEqualTo("\"a b\"");
613+
}
614+
453615
#endif
454616
}

0 commit comments

Comments
 (0)