Powershell 7.0
Since the update from Powershell 6.2.3 to 7.0 Invoke-WebRequest will not return Images anymore.
Invoke-WebRequest -Uri https://example.test/ -UseDefaultCredentials
Expected behavior

Actual behavior

PS C:\Program Files\PowerShell\7> $PSVersionTable
Name Value
---- -----
PSVersion 7.0.0
PSEdition Core
GitCommitId 7.0.0
OS Microsoft Windows 10.0.17763
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
We're you getting this in 6.2? The screenshot you're showing looks like it came from Windows PowerShell (which would be v5.1).
The parsing used to find such elements in the page in 5.1 is not usable in .NET Core or PS v6+ as it relies entirely on communication with an Internet Explorer session on the back end. PowerShell was not doing that parsing.
This could be considered as a feature request for the existing behaviour, but it's probably safe to say that specific way of handling in will not be used again. It's simply not feasible on anything other than Windows, and as IE grows older the chances it keeps working gradually get smaller anyway.
@vexx32 thanks for your response.
Yes, in 6.2 it still worked. I tested it in 5.1 as well and took the screenshot.
I can repo on 7.0:
Invoke-WebRequest https://yandex.ru
It comes from https://github.com/PowerShell/PowerShell/commit/c64a28eaf19f0b97edffd53222430687f3c59823
/cc @TravisEz13
I guess I haven't used these cmdlets much with regular webpages (mostly API work for me!), I didn't even think we had an Images property anymore.
But yeah, that regex change in that commit will probably skip over quite a few valid images.
The original regex was:
<img\s+[^>]*>
which was replaced with
<img\s+[^\s>]*>
I'd probably instead suggest:
<img\s+[^>]*?>
There're probably a lot of scenarios where an image has more than one space inside the tag -- <img src="$url" class="$class"/> I'm sure being a common one.
Good catch @iSazonov!
Since it comes from compliance fix I'd want to get confirmation from @TravisEz13 and @PaulHigin .
Please don't write the regex so that it has two terms looking for the same thing more than once. This will regress the fix.
<img\s[^>]*?> might work
@vexx32, @iSazonov, or @pronerd2020 Do any of you want to work on this?
I can submit a quick PR. Not sure if there's a good way to regression test this; if you have any idea how we could add a test for this @TravisEz13 I'd appreciate some ideas on that front. 馃檪
There is already a test to verify that the perf of the regex doesn't become pathologic.
:tada:This issue was addressed in #12099, which has now been successfully released as v7.1.0-preview.2.:tada:
Handy links:
:tada:This issue was addressed in #12099, which has now been successfully released as v7.0.1.:tada:
Handy links:
Most helpful comment
<img\s[^>]*?>might work