PowerShell / PowerShell/PSScriptAnalyzer

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

Đang mở
#1,667 0 bình luận 2 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Area - Rules Issue - Enhancement Up-for-Grabs
Ngôn ngữ chính
C#
Star
2.2k
Fork
414
Merge trung bình
13 giờ 1 phút
Pull request đã merge (30 ngày)
2

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Issue này nhắm đến PSScriptAnalyzer và mẫu PowerShell [xml](Get-Content <File>). Hãy bắt đầu bằng cách tìm các triển khai quy tắc và các bài kiểm thử hiện có của trình phân tích cho chẩn đoán dựa trên mẫu; được xem là hoàn thành khi mẫu này bị cảnh báo và dạng được đề xuất để tải XML được báo cáo nhất quán trên Windows PowerShell 5.1 và PowerShell 7.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
powershell
Lĩnh vực
tooling
Loại issue
Tính năng
Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
38/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.