PowerShell / PowerShell/PSScriptAnalyzer

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

Aberta
#1,667 0 comentários 2 reações 0 responsáveis Ver no GitHub

Ninguém assumiu esta issue ainda.

Area - Rules Issue - Enhancement Up-for-Grabs
Linguagem predominante
C#
Estrelas
2.2k
Forks
415
Merge médio
13h 1min
PRs com merge (30d)
2

Descrição

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.

Guia de contribuição

Abrir o guia de contribuição

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Direção de pesquisa

A issue tem como alvo o PSScriptAnalyzer e o padrão do PowerShell [xml](Get-Content <File>). Comece encontrando as implementações de regras e os testes existentes do analisador para diagnósticos baseados em padrões; considera-se concluído quando o padrão gerar um aviso e a forma sugerida de carregamento de XML for relatada de maneira consistente no Windows PowerShell 5.1 e no PowerShell 7.

Escrita pelo modelo de indexação a partir do texto da issue.

Avaliação

Stack de tecnologia
powershell
Domínio
tooling
Tipo de issue
Funcionalidade
Dificuldade
3/5
Tempo estimado
1-2 dias
Status de atividade
Estagnada
Clareza
Razoavelmente clara
Facilidade para iniciantes
38/100

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.