PowerShell / PowerShell/PSScriptAnalyzer
Rule Idea: Warn on `[xml](Get-Content <File>)` pattern
Nessuno ha ancora preso questa issue.
- Lingua principale
- C#
- Stelle
- 2.2k
- Fork
- 414
- Merge medio
- 13h 1m
- PR unite (30g)
- 2
Descrizione
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.
-
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
-
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.
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Direzione di ricerca
La issue riguarda PSScriptAnalyzer e il pattern di PowerShell [xml](Get-Content <File>). Inizia trovando le implementazioni delle regole e i test esistenti dell'analizzatore per le diagnostiche basate su pattern; il lavoro è completato quando viene emesso un avviso per il pattern e la forma suggerita per il caricamento di XML viene segnalata in modo coerente in Windows PowerShell 5.1 e PowerShell 7.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- powershell
- Ambito
- tooling
- Tipo di issue
- Funzionalità
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 38/100