Reader should be capable of transparent EOL normalization

Aperta
#1,003 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Attiva
Stack tecnologico
rust
Ambito
backend

Direzione di ricerca

Start by tracing the Reader constructors and the XML content methods mentioned in the issue, then read XML 1.0 Section 2.11 and the linked follow-up issue. The proposed change spans buffering, decoding, normalization, zero-copy behavior, and compatibility for noncompliant input; define the desired API and tradeoffs before implementation. Done means reader behavior follows the selected XML specification consistently, with an explicit approach for disabling normalization where needed.

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

Descrizione

enhancement

Followup to https://github.com/tafia/quick-xml/issues/158

Per XML specification, all XML readers should perform line-ending normalization as a pre-processing step (or functionally behaving as if it were a pre-processing step - XML 1.0 Section 2.11)

This is both an ergonomic issue and also a minor correctness issue, because EOL normalization is blind to document contents and therefore also applies within elements, e.g. <?xml\r?> ought to be parsed as <?xml\n?> - which libxml2 does in fact do.

It's an ergonomic issue in the sense that a user should not need to care about it - the .xml_content(), .xml10_content(), .xml11_content() functions etc. ought to be superfluous and are potentially error prone. The user also shouldn't need to track the version declared in the declaration - they likely just want the document to be processed according to the correct specification per the declaration or according to the one they specify, but that need not change on a per-element basis.

Performing universal EOL normalization as a pre-processor pass through a bufffer would reduce total allocations and likely improve performance on average, while improving ergonomics and compliance.

The mechanism could also likely be used as a base upon which line/column tracking (https://github.com/tafia/quick-xml/issues/109) could be added.

Potentially troublesome aspects:

  • For users who process noncompliant "almost-XML" documents that contain binary blobs, we would need a way to disable it, possibly document-wide, or perhaps just during the usage of stream().
  • We might want to make the current Reader constructors from_reader(), from_str(), from_bytes() methods buffered by-default, and perhaps add a new constructor which takes only a pre-processed XmlDoc type or similar where decoding + normalization has already happened, allowing proper zero-copy. If we keep zero-copy (which isn't really zero-copy in practice) at all - maybe worth doing some benchmarking to see how much time is actually saved vs. just having a buffered path. XML parsing is easily 25-50x slower than copying the bytes around once or twice anyway, and the XmlSource code + macros are all quite complex.
Lingua principale
Rust
Stelle
1.6k
Fork
299
Merge medio
2g 4h
PR unite (30g)
9

Preparare l'ambiente

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 tafia/quick-xml

Tutte le issue di tafia/quick-xml

Issue simili

Altre issue su Rust

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.