A processing instruction with no target passes validation, then the builder prints invalid XML

Đang mở Phù hợp với người mới
#927 2 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 4 ngày

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

Từ ngày 17/11/2026.

  • #928 của @bardrop — đ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
78/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, node.js
Lĩnh vực
backend, testing-qa

Hướng nghiên cứu

Bắt đầu với đường dẫn xác thực processing instruction trong XMLValidator, sau đó so sánh cách xử lý <?x?> và <? ?> với ngữ pháp XML PI được mô tả trong issue. Kiểm tra hành vi của parser và builder bằng ví dụ Node.js được cung cấp. Công việc hoàn tất khi quá trình xác thực từ chối các trường hợp target không hợp lệ, hoặc parsing bỏ qua chúng, để builder không tạo ra XML không hợp lệ.

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 online tool?
  • Have you checked the docs for helpful APIs and examples?
Description

Hello,

While fuzzing [email protected] (the latest version) with Termo, a fuzzer I'm developing, I found that XMLValidator accepts a processing instruction with no target name (<?>x?>). XMLParser then returns a node with an empty tag name, and XMLBuilder turns it into <></>, which is not XML:

// [email protected], Node.js v26.13.0
const { XMLValidator, XMLParser, XMLBuilder } = require('fast-xml-parser');
const options = { ignoreAttributes: false, preserveOrder: true };
const input = '<?>x?><r/>';
console.log(XMLValidator.validate(input));            // true
const parsed = new XMLParser(options).parse(input);
console.log(JSON.stringify(parsed));                  // [{"":[{"#text":""}]},{"r":[]}]
const built = new XMLBuilder(options).build(parsed);
console.log(built);                                   // <></><r></r>
console.log(XMLValidator.validate(built) === true);   // false

Without a target (<?>) validation already fails as it should. With a body (<?>x?>) it passes. The XML spec requires a name right after <? (PI ::= '<?' PITarget (S ...)? '?>').

<? ?><r/> is similar: it validates, and parses into a node named "?", which the builder prints as <??>.

Expected: the validator rejects a processing instruction with no target (or else the parser skips it), so the builder never prints an element with an empty name.

Happy to test a fix against these inputs if it helps.

If you'd like me to keep fuzzing fast-xml-parser (other parts of the API, or re-checking after a fix), feel free to reach out. I'd be glad to keep working on it with you.

Thanks!

Ngôn ngữ chính
JavaScript
Star
3.1k
Fork
410
Merge trung bình
4 ngày 15 giờ
Pull request đã merge (30 ngày)
8

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.