Escaping `XmlNameProcessors` write a colon in XML names as-is, producing output that can not be read back
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 85/100
Direzione di ricerca
Guarda Base64NameProcessor e ReplaceNameProcessor. Modifica i pattern di regex VALID_XML_NAME e gli insiemi di caratteri consentiti per escludere i due punti, in modo che nomi come a:b vengano escapati o sostituiti. Aggiorna il metodo encodeName() di conseguenza. Aggiungi test di andata e ritorno per verificare che i nomi che contengono due punti si serializzino in XML valido e si deserializzino senza StreamReadException.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Describe the bug
Both escaping processors from XmlNameProcessors treat a colon as a valid XML name character, so a name that contains one is written out verbatim:
Base64NameProcessor.VALID_XML_NAMEis[a-zA-Z_:]([a-zA-Z0-9_:.-])*, i.e. a name holding a colon counts as already valid and is not escapedReplaceNameProcessorkeeps:in both of its allowed sets (^[^a-zA-Z_:],[^a-zA-Z0-9_:-])
Output is namespace-aware, though, so the colon comes back as a prefix that nothing declares and the document can no longer be read by this module:
<DTO><badMap><a:b>xyz</a:b></badMap></DTO>
tools.jackson.core.exc.StreamReadException:
Undeclared namespace prefix "a"
at [row,col {unknown-source}]: [1,18]
at [Source: (String)"<DTO><badMap><a:b>xyz</a:b></badMap></DTO>"; line: 1, column: 19]
Caused by: com.ctc.wstx.exc.WstxParsingException: Undeclared namespace prefix "a"
Keys like a:b:c or :leading are not even well-formed, so they fail in the Stax reader before namespace resolution.
The javadoc of both processors lists the colon as "only exposed if underlying parser is in non-namespace-aware mode", but encoding has no knowledge of which parser will read the result back, and newAlwaysOnBase64Processor() already handles the same keys cleanly. Round-tripping names that are not valid XML names is what these two processors exist for, so the colon looks like an oversight in the allowed sets rather than a deliberate exception.
Version information
3.3.0-SNAPSHOT (3.x). The allowed sets have looked this way since the mechanism was added (#531), so 3.0/3.1/3.2 and 2.x behave the same.
Reproduction
public static class DTO {
public Map<String, String> badMap = new HashMap<>();
}
private XmlFactory xmlFactory(XmlNameProcessor nameProcessor) {
return XmlFactory.builder().xmlNameProcessor(nameProcessor).build();
}
@Test
public void colonInNameRoundTrips() throws Exception {
XmlMapper mapper = XmlMapper.builder(
xmlFactory(XmlNameProcessors.newBase64Processor())).build();
DTO dto = new DTO();
dto.badMap.put("a:b", "xyz");
String xml = mapper.writeValueAsString(dto);
// writes <DTO><badMap><a:b>xyz</a:b></badMap></DTO>
mapper.readValue(xml, DTO.class); // StreamReadException: Undeclared namespace prefix "a"
}
Same for newReplacementProcessor(), which writes <a:b> rather than replacing the colon. newAlwaysOnBase64Processor() is fine, since it escapes every name.
Expected behavior
A name containing a colon should be escaped (base64, still a lossless round trip) or replaced, like any other character that cannot appear in a written XML name, so that what these processors write can be read back.
Only encodeName() would need to change: decodeName() keys off the prefix for base64 and is a no-op for replacement, so names read from a non-namespace-aware parser are still passed through untouched.
Additional context
PR #921 has the fix plus round-trip tests. Targeted at 3.x since it changes what gets written for these names.
- Lingua principale
- Java
- Stelle
- 636
- Fork
- 250
- Merge medio
- 7h 10m
- PR unite (30g)
- 8
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
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di FasterXML/jackson-dataformat-xml
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 55/100
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
FasterXML/jackson-dataformat-xml#931 · 3 commenti ·
-
XmlMapper with `FAIL_ON_UNKNOWN_PROPERTIES` fails on whitespace-only elementForse già presa @arimu1 l’ha presa 89 giorni fa. Apertato-evaluate
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
-
3.x
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
FasterXML/jackson-dataformat-xml#787 · 1 commento ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 35/100
FasterXML/jackson-dataformat-xml#712 · 3 commenti ·
Tutte le issue di FasterXML/jackson-dataformat-xml
Issue simili
-
Cleanup: restore the interrupt flag in AiFailureAnalyzerForse già presa @Rishankgupta08 l’ha presa oggi. Apertagood first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
seleniumboot/selenium-boot#258 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 88/100
johanhaleby/occurrent#1505 ·
I maintainer di solito rispondono entro 1 giorno
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
FasterXML/jackson-databind#6443 ·
I maintainer di solito rispondono entro 1 giorno
-
Docs: 2 broken linksAperta
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 78/100
I maintainer di solito rispondono entro 1 giorno