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' {