XMLValidator accepts raw < and & in attribute values

Đang mở Phù hợp với người mới
#900 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 3 ngày

@jeromeyyy đang làm issue này rồi.

Từ ngày 4/11/2026.

  • #913 của @jeromeyyy — đang mở

Đánh giá

Độ khó
2/5
Thời gian dự kiến
1-3 giờ
Mức phù hợp với người mới
72/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
javascript
Lĩnh vực
data

Hướng nghiên cứu

Bắt đầu từ hàm validateAttributeString của bộ kiểm tra, theo issue thì hàm này nhận giá trị trong dấu ngoặc kép từ bộ quét token thuộc tính nhưng không kiểm tra '<' thô hoặc tham chiếu '&' sai định dạng. Chạy ba đầu vào trong issue qua XMLValidator.validate và parse(xml, true) để xác nhận hành vi hiện tại. Hoàn thành khi hai đầu vào đầu tiên không vượt qua kiểm tra, đối chứng &amp; vẫn đạt và các test hiện có vẫn xanh.

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

Mô tả

  • Are you running the latest version?
  • Have you included sample input, output, error, and expected output?
  • Have you checked if you are using correct configuration?
  • Did you try the online tool?
  • Have you checked the docs for helpful APIs and examples?
Description

On 5.11.2 (current master at cf66a9658004553bc740616e6c7a4912e7e9aab6), XMLValidator accepts raw ampersands and less-than signs inside quoted attribute values. XML 1.0's AttValue grammar excludes both literal characters there; an ampersand must begin a reference. This concerns attribute values, whereas #214 reported a stray ampersand in element text.

Input
<a x="&"/>
<a x="<"/>
<a x="&amp;"/>

The last input is a valid control.

Code
const { XMLParser, XMLValidator } = require('fast-xml-parser');

for (const xml of ['<a x="&"/>', '<a x="<"/>', '<a x="&amp;"/>']) {
  console.log(xml, XMLValidator.validate(xml));
}
console.log(new XMLParser({ ignoreAttributes: false }).parse('<a x="&"/>', true));
Output

XMLValidator.validate returns true for all three inputs. Parsing the raw-ampersand input with validation enabled returns { a: { '@_x': '&' } }. The official online validator also reports "Valid XML" for both malformed inputs.

Expected data

The first two inputs should return a validation error, and parse(xml, true) should reject them. The escaped control should remain valid. The attribute token scanner extracts the quoted value, but validateAttributeString does not check that value for raw '<' or malformed '&' references.

Would you like to work on this issue?

  • Yes
  • No
Ngôn ngữ chính
JavaScript
Star
3.1k
Fork
404
Merge trung bình
2 ngày 1 giờ
Pull request đã merge (30 ngày)
5

Chuẩn bị môi trường

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.

Issue khác của NaturalIntelligence/fast-xml-parser

Tất cả issue của NaturalIntelligence/fast-xml-parser

Issue tương tự

Thêm issue về JavaScript

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.