From 107fd7ab1fffc755c29ccfc03a24a7bd5ed196cb Mon Sep 17 00:00:00 2001
From: Austin Farmer <5827236+farmerau@users.noreply.github.com>
Date: Tue, 2 Nov 2021 12:39:28 -0400
Subject: [PATCH] Add support to web cmdlets for open-ended input tags (#16193)
---
.../BasicHtmlWebResponseObject.Common.cs | 2 +-
.../WebCmdlets.Tests.ps1 | 42 +++++++++++++++++++
2 files changed, 43 insertions(+), 1 deletion(-)
diff --git a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/BasicHtmlWebResponseObject.Common.cs b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/BasicHtmlWebResponseObject.Common.cs
index 969dd8231c..07982009a0 100644
--- a/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/BasicHtmlWebResponseObject.Common.cs
+++ b/src/Microsoft.PowerShell.Commands.Utility/commands/utility/WebCmdlet/Common/BasicHtmlWebResponseObject.Common.cs
@@ -219,7 +219,7 @@ namespace Microsoft.PowerShell.Commands
if (s_inputFieldRegex == null)
{
- s_inputFieldRegex = new Regex(@"]*(/>|>.*?)",
+ s_inputFieldRegex = new Regex(@"]*(/?>|>.*?)",
RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.Compiled);
}
diff --git a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1 b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1
index 5f4f5c7728..e4973f5515 100644
--- a/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1
+++ b/test/powershell/Modules/Microsoft.PowerShell.Utility/WebCmdlets.Tests.ps1
@@ -1933,6 +1933,48 @@ Describe "Invoke-WebRequest tests" -Tags "Feature", "RequireAdminOnWindows" {
$response = Invoke-WebRequest -Uri $dosUri
$response.Images | Should -Not -BeNullOrEmpty
}
+
+ $singleInputExpected = @(
+ @{ Name = 'foo'; Value = 'bar' }
+ )
+
+ It 'correctly parses input tag(s) for ``' -TestCases @(
+ @{
+ Markup = "";
+ ExpectedFields = $singleInputExpected
+ },
+ @{
+ Markup = "";
+ ExpectedFields = $singleInputExpected
+ },
+ @{
+ Markup = "baz";
+ ExpectedFields = $singleInputExpected
+ }
+ @{
+ Markup = "";
+ ExpectedFields = @(
+ @{ Name = 'item1'; Value = 'bar'},
+ @{ Name = 'item2'; Value = 'foo' },
+ @{ Name = 'item3'; Value = $null },
+ @{ Name = 'item4'; Value = 'fu' },
+ @{ Name = 'item5'; Value = 'bahr' }
+ )
+ }
+ ) {
+ param($markup, $expectedFields)
+ $query = @{
+ contenttype = 'text/html'
+ body = "${markup}"
+ }
+ $uri = Get-WebListenerUrl -Test 'Response' -Query $query
+ $response = Invoke-WebRequest -Uri $uri -UseBasicParsing
+ $response.Error | Should -BeNullOrEmpty
+ ForEach ($expectedField in $expectedFields) {
+ $actualField = $response.InputFields.FindByName($expectedField.Name)
+ $actualField.Value | Should -Be $expectedField.Value
+ }
+ }
}
Context "Denial of service" -Tag 'DOS' {