镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

Skip comments and processing instructions in ListBasedXMLEventReader#getElementText - #37563

Open
lejuho wants to merge 1 commit into
spring-projects:mainfrom
lejuho:xml-elementtext-comments
Open

lejuho wants to merge 1 commit into
spring-projects:mainfrom
lejuho:xml-elementtext-comments

Conversation

@lejuho

@lejuho lejuho commented Oct 23, 2026

Copy link
Copy Markdown
Contributor

ListBasedXMLEventReader#getElementText() currently throws an XMLStreamException ("Unexpected non-text event") when a comment or processing instruction appears within the text content of an element, e.g. <bar>ba<!-- comment -->z</bar>. The JDK's XMLEventReader returns "baz" for the same input.

The contract of XMLStreamReader#getElementText() (which XMLEventReader#getElementText() refers to) skips COMMENT and PROCESSING_INSTRUCTION events, and Spring's own AbstractXMLStreamReader#getElementText() and ListBasedXMLEventReader#nextTag() already skip them. This change aligns ListBasedXMLEventReader#getElementText() with that behavior; other non-text events (e.g. a nested START_ELEMENT) still result in an exception.

Tests added for comments, processing instructions, comment-only content, and a nested element still throwing.

…getElementText

ListBasedXMLEventReader#getElementText() threw an XMLStreamException
when a comment or processing instruction appeared within the text
content of an element. As specified by XMLStreamReader#getElementText()
and as already implemented in AbstractXMLStreamReader#getElementText()
and ListBasedXMLEventReader#nextTag(), such events are now skipped.

Signed-off-by: lejuho <zedd1324@gmail.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Oct 23, 2026
@sbrannen sbrannen added the in: core Issues in core modules (aop, beans, core, context, expression) label Oct 26, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: core Issues in core modules (aop, beans, core, context, expression) status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants