`preserveOrder: true` with `format: true`: output starts with a line break and has none at the end — intended?

オープン
#30 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
54/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
javascript
領域
backend

調査の方向性

Start with spec/j2x_ordered_spec.js and the toXml() formatting path mentioned in the issue. Compare the ordered and keyed outputs for the same input, including the case with ?xml, and check how the existing specs define the leading and trailing line breaks. Done means the intended behavior is decided and the output and specs agree.

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

説明

Description

With format: true, the ordered mode and the keyed mode put line breaks in different places for the same document:

  • The ordered mode starts the output with a line break and doesn't end it with one.
  • The keyed mode starts directly with the root element and ends with a line break.

When the input starts with ?xml, the ordered mode writes no line break before the declaration. So the ordered mode isn't consistent with itself either. The top-level indentation in toXml() is the line break itself, and only ?xml is exempt from it (tempInd).

Code
import XMLBuilder from "fast-xml-builder"; // 1.3.1

const ordered = new XMLBuilder({ format: true, preserveOrder: true, ignoreAttributes: false });
const keyed = new XMLBuilder({ format: true });

ordered.build([{ root: [{ a: [{ "#text": "1" }] }] }]);
keyed.build({ root: { a: "1" } });
ordered.build([
  { "?xml": [], ":@": { "@_version": "1.0" } },
  { root: [{ a: [{ "#text": "1" }] }] },
]);
Output
"\n<root>\n  <a>1</a>\n</root>"
"<root>\n  <a>1</a>\n</root>\n"
"<?xml version=\"1.0\"?>\n<root>\n  <a>1</a>\n</root>"
Question

Several specs expect the leading line break, for example "should build formatted XML" in spec/j2x_ordered_spec.js. So I'm not sure whether this is intended. Would you accept a change that makes the ordered mode behave like the keyed mode, either by default in a major version or behind an option? I'd be happy to open a PR.

Would you like to work on this issue?

  • Yes
  • No
主要言語
JavaScript
スター
22
フォーク
9
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

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

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

似ている issue

JavaScript の issue をもっと見る

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

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