apache / apache/maven-shared-utils
XMLEncode: illegal XML control characters not encoded
- Dominant language
- Java
- Stars
- 36
- Forks
- 32
- Avg merge
- 8h 1m
- Merged PRs (30d)
- 13
Description
`XMLEncode.xmlEncodeTextAsPCDATA()` passes characters in the range U+0000-U+001F (excluding U+0009 TAB, U+000A LF, U+000D CR) through unencoded in the `default` branch of its switch statement. These characters are illegal in XML 1.0 and will cause XML parsers to reject the output.
The `default` case at line 112 just does `n.append(c)` — it should instead encode these characters as `&#xHH;` numeric character references. The explicitly handled cases (`&`, `<`, `>`, `"`, `'`, `\r`, `\n`) cover the legal control chars, but `\0`, `\1`-`\b`, `\v`, `\f`, `\u000E`-`\u001F` all slip through.
This affects both attribute values (via `PrettyPrintXMLWriter.addAttribute()`) and text content (via `PrettyPrintXMLWriter.writeText()`).
Fix: add a check in the `default` case to encode illegal XML control characters.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in XMLEncode.xmlEncodeTextAsPCDATA(), especially the default branch around line 112, and trace its use from PrettyPrintXMLWriter.addAttribute() and writeText(). Done means illegal XML 1.0 control characters are emitted as numeric character references in both attribute values and text content, while the explicitly handled legal characters remain unchanged.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Active
- Clarity
- Clearly specified
- Newbie friendliness
- 86/100