Whitespaces around character entities
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 35/100
Línea de trabajo
Start by reading the Config::trim_text behavior and the deserializer path that handles text and decoded character entities; the report includes a reproducer using NsReader and quick_xml::de::Deserializer::borrowing. Check existing tests for trimming and entity decoding, then determine whether a configuration option can preserve spaces around entities while trimming only leading and trailing text. Done means the reproducer retains those internal spaces without losing global edge trimming.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I maintain a large codebase that used quick-xml for years across hundreds of structs.
After switching from 0.37.5 to 0.38, I hit the already well-known whitespace issues. 0.38.1 introduced Config::trim_text which saved me from touching thousands of fields, but now I found the next caveat: XML character entities make trim_text(true) trim more than needed:
#!/usr/bin/env cargo
---
[dependencies]
serde = { version = "1", features = ["derive"] }
quick-xml = { version = "0.38", features = ["serialize"] }
quick-xml-old = { package = "quick-xml", version = "0.37", features = ["serialize"] }
---
use quick_xml::reader::NsReader;
use serde::Deserialize;
use std::result::Result;
#[derive(Debug, Deserialize)]
struct Root {
bar: String,
}
pub fn from_str_trim_text<'de, T>(s: &'de str) -> Result<T, Box<dyn std::error::Error>>
where
T: Deserialize<'de>,
{
let mut reader = NsReader::from_str(s);
let config = reader.config_mut();
config.trim_text(true); // Trims also spaces around decoded &
config.expand_empty_elements = true;
let mut de = quick_xml::de::Deserializer::borrowing(reader);
Ok(T::deserialize(&mut de)?)
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let xml = r#"
<root>
<bar>
Foo & Bar & Baz Qux Quux
</bar>
</root>"#;
let old: Root = quick_xml_old::de::from_str(xml)?;
let new: Root = quick_xml::de::from_str(xml)?;
let new_trimming: Root = from_str_trim_text(xml)?;
println!("Old: {}", old.bar); // "Foo & Bar & Baz Qux Quux"
println!("New: {}", new.bar); // "\n Foo & Bar & Baz Qux Quux\n "
println!("New trimming: {}", new_trimming.bar); // "Foo&Bar&Baz Qux Quux"
Ok(())
}
(cargo +nightly -Zscript example.rs)
I know this is documented behavior (thank you), so I'm not calling it a bug. I’m looking for a solution to preserve "internal" spaces (e.g, around the decoded entities) while still trimming leading/trailing whitespace globally.
The only workaround that comes to my mind atm is either introducing a newtype or using deserialize_with, which are both rather error-prone in a mature codebase like mine and require tons of work.
If there is no existing solution right now, I could try to implement a feature (e.g., a new config option?) if the maintainers think it is a good idea.
- Lenguaje dominante
- Rust
- Estrellas
- 1.6k
- Forks
- 299
- Merge medio
- 2 d 4 h
- PR fusionados (30 d)
- 9
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de tafia/quick-xml
-
Parser accepts an empty element or attribute namePosiblemente ocupada @ychampion la tomó hace 1 día. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
DecodingReader::set_encoding panics when the XML declaration is longer than 64 bytesPosiblemente ocupada @emschwartz la tomó hace 4 días. Abiertobug encoding
Dificultad 4/5 3-5 días Aptitud para principiantes 30/100
tafia/quick-xml#1040 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
encoding optimization
Dificultad 4/5 3-5 días Aptitud para principiantes 55/100
tafia/quick-xml#1039 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
optimization question
Dificultad 4/5 3-5 días Aptitud para principiantes 52/100
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 4/5 1-2 días Aptitud para principiantes 53/100
tafia/quick-xml#1035 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de tafia/quick-xml
Issues similares
-
[Bug]: opencode_go chat route drops reasoning_effort (even 'none'), while the same endpoint honors it via custom_llm_provider=openaiPosiblemente ocupada @arvindkumar-ship-it la tomó hoy. Abiertollm translation
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
BerriAI/litellm#51871 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
comp-formats
Dificultad 2/5 Medio día Aptitud para principiantes 64/100
ClickHouse/ClickHouse#131694 ·
Los mantenedores suelen responder en 1 día
-
cli: `execCargoMetadata` decodes stdout per chunk, corrupting non-ASCII paths across pipe boundariesAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
C-Bug S-Needs-Triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
bevyengine/bevy#26558 ·
Los mantenedores suelen responder en 2 días