Skip to content

BasicHtmlWebResponseObject does not parse self-closing <input> tags #16126

Description

@richard-browne

Prerequisites

Steps to reproduce

Using 'Invoke-WebRequest -UseBasicParsing', the returned BasicHtmlWebResponseObject does not parse <input> tags correctly. It assumes they will be closed with a '/>' or '</input>'. However in html, neither the slash nor closing tag is required/legal depending on your html flavour.

The bug is in BasicHtmlWebResponseObject.Common.cs. The s_inputFieldRegex is set to:

@"<input\s+[^>]*(/>|>.*?</input>)"

But it should be:

@"<input\s+[^>]*(/>|>|>.*?</input>)"

Looking at the history the problem has been there since PowerShell 3.0, and remains unfixed in the latest PowerShell Core.

Expected behavior

Suppose we will perform an HTTP GET thusly:

`$response = Invoke-WebRequest -UseBasicParsing -Url 'https://localhost/test.html'`

And the returned html is:

`<html><body><input name='foo' value='mcgoo'></body>/</html>`

$response.InputFields should contain 1 element. $response.InputFields.FindByName('foo') should return the element.

Actual behavior

Instead $response.InputFields contains no elements, and $response.InputFields.FindByName('foo') returns $null.

Error details

No response

Environment data

Name                           Value
----                           -----
PSVersion                      7.0.3
PSEdition                      Core
GitCommitId                    7.0.3
OS                             Microsoft Windows 10.0.18363
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Visuals

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugIssue has been identified as a bug in the productNeeds-TriageThe issue is new and needs to be triaged by a work group.Resolution-FixedThe issue is fixed.Up-for-GrabsUp-for-grabs issues are not high priorities, and may be opportunities for external contributorsWG-Cmdlets-Utilitycmdlets in the Microsoft.PowerShell.Utility module

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions