Skip to content

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

Closed

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

Activity

  1. added
    Needs-Triage
    on Sep 21, 2021
  2. added
    Issue-Bug
    Up-for-Grabs
    on Sep 21, 2021
  3. farmerau commented on Oct 4, 2021

    @farmerau
    Contributor

    I'll try to take a look into this.

  4. farmerau commented on Nov 6, 2021

    @farmerau
    Contributor

    richard-browne The fix for this was merged.

  5. CarloToso commented on Dec 2, 2022

    @CarloToso
    Contributor

    Ilya (@iSazonov) this is no longer an issue, could you please close it?

  6. ghost closed this as completedon Dec 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Issue-BugNeeds-TriageResolution-FixedUp-for-GrabsWG-Cmdlets

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions