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

オープン 初心者向け
#927 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 4 日以内に返信

@bardrop がすでに取り組んでいます。

2026年11月17日 から。

  • #928 @bardrop による — オープン

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
78/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
javascript, node.js

調査の方向性

まず XMLValidator の処理命令の検証経路を確認し、<?x?> と <? ?> の処理を、issue で説明されている XML PI 文法と比較してください。提示された Node.js の例を使って、parser と builder の動作を確認してください。検証で無効な target のケースが拒否されるか、parsing でスキップされ、その結果 builder が無効な XML を生成しなくなれば完了です。

索引モデルが issue の本文から書いたものです。

説明

  • 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!

主要言語
JavaScript
スター
3.1k
フォーク
410
平均マージ
4日 15時間
マージ済み PR(30日)
8

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

NaturalIntelligence/fast-xml-parser のほかの issue

NaturalIntelligence/fast-xml-parser の issue をすべて見る

似ている issue

JavaScript の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。