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

Aperta
#30 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
54/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
javascript
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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
Lingua principale
JavaScript
Stelle
22
Fork
9
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di NaturalIntelligence/fast-xml-builder

Tutte le issue di NaturalIntelligence/fast-xml-builder

Issue simili

Altre issue su JavaScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.