PowerShell / PowerShell/PSScriptAnalyzer

Rule Idea: Warn on `[xml](Get-Content <File>)` pattern

Offen
#1,667 0 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Area - Rules Issue - Enhancement Up-for-Grabs
Vorherrschende Sprache
C#
Sterne
2.2k
Forks
414
Ø Merge
13 Std. 1 Min.
Gemergte PRs (30 T.)
2

Beschreibung

Summary of the new feature

Warn on Pattern: [xml](Get-Content <File>)
Suggest Pattern: $a = [xml]::new(); $a.Load(<File>)

This pattern is currently in wide use, but it has some problems and should be discouraged.

  1. This pattern, due to using Get-Content, has problems if the (perfectly valid) xml file being parsed is not utf8 encoded. See: https://github.com/PowerShell/PowerShell/issues/14505 & https://stackoverflow.com/questions/65263942/how-to-load-or-read-an-xml-file-using-convertto-xml-and-select-xml/65264118#65264118

  2. This pattern is very inefficient. I know that PSSA does not generally worry about this - but since the encoding issue above exists, feels worth it to mention. Testing against a ~1mb file shows [xml](Get-Content <File>) as ~12x slower, and against a 170mb file as 22x slower (loading took 46 seconds!).

What is the latest version of PSScriptAnalyzer at the point of writing
PSSA 1.19.1

Powershell Versions
This currently affects both Windows Powershell 5.1 and Powershell 7.

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Rechercherichtung

Das Issue zielt auf PSScriptAnalyzer und das PowerShell-Muster [xml](Get-Content <File>) ab. Beginne damit, die vorhandenen Regelimplementierungen und Tests des Analyzers für musterbasierte Diagnosen zu finden; erledigt ist die Aufgabe, wenn für das Muster eine Warnung ausgegeben und die empfohlene Form zum Laden von XML unter Windows PowerShell 5.1 und PowerShell 7 konsistent gemeldet wird.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
powershell
Bereich
tooling
Issue-Typ
Feature
Schwierigkeit
3/5
Geschätzter Aufwand
1-2 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
38/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.