`attributesGroupName` writes `null` and `undefined` attribute values as text

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

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

評価

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

調査の方向性

src/fxb.jsから始め、170~183行目付近の個別キー属性の処理と、281~288行目付近のattributesGroupName分岐を比較してください。グループ化された属性に関する既存のテストを確認し、nullとundefinedの値を対象とするテストを追加してください。グループ化された属性と個別キー属性の両方でこれらの値が省かれ、残りの属性の出力が期待されるXMLと一致すれば完了です。

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

説明

Summary

Version: 1.3.2
Context: I group attributes so that attribute keys don't need the @_ prefix and can't collide with child element names.

With attributesGroupName set, an attribute whose value is null or undefined is written as the text "null" or "undefined". Without a group name, the same values are left out.

Reproduction

import XMLBuilder from 'fast-xml-builder';

const perKey = new XMLBuilder({ ignoreAttributes: false });
console.log(perKey.build({ item: { '@_a': 'x', '@_b': null, '@_c': undefined } }));
// <item a="x"></item>

const grouped = new XMLBuilder({ ignoreAttributes: false, attributesGroupName: '$' });
console.log(grouped.build({ item: { $: { a: 'x', b: null, c: undefined } } }));
// <item a="x" b="null" c="undefined"></item>

Expected

Both print <item a="x"></item>.

Additional details

When building, the builder skips undefined and null values for individually keyed attributes (src/fxb.js#L170-L183), which came from NaturalIntelligence/fast-xml-parser#598 for NaturalIntelligence/fast-xml-parser#585. The attributesGroupName branch (src/fxb.js#L281-L288) passes every value in the group to buildAttrPairStr without that check. attributeValueProcessor can't drop an attribute, so no option works around it.

主要言語
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 を短くまとめたダイジェスト。