8000 fixes #107: Escape namespace URIs when writing XML by guusdk · Pull Request #203 · dom4j/dom4j · GitHub
[go: up one dir, main page]

Skip to content

fixes #107: Escape namespace URIs when writing XML - #203

Open
guusdk wants to merge 1 commit into
dom4j:masterfrom
guusdk:fix/issue-107-escape-namespace-uri
Open

guusdk wants to merge 1 commit into
dom4j:masterfrom
guusdk:fix/issue-107-escape-namespace-uri

Conversation

@guusdk
@guusdk guusdk commented Oct 2, 2026
Copy link
Copy Markdown

Namespace URIs were written into the xmlns attribute without escaping them, unlike regular attribute values. A URI like

urn:example"/><injected foo="bar">

would close the element early, giving you XML that is either malformed or, worse, parses into a different structure than the one you wrote.

Namespace URIs are now escaped the same way attribute values are. When writing with XMLWriter, the declaration now also uses the configured attribute quote character instead of a hard-coded double quote.

Namespace's asXML() also wrote the URI unescaped. It now escapes it. (It has no output format to take a quote character from, so it keeps using double quotes.)

Fixes #107

Namespace URIs were written into the xmlns attribute without escaping them, unlike regular attribute values. A URI like

    urn:example"/
8000
><injected foo="bar">

would close the element early, giving you XML that is either malformed or, worse, parses into a different structure than the one you wrote.

Namespace URIs are now escaped the same way attribute values are. When writing with XMLWriter, the declaration now also uses the configured attribute quote character instead of a hard-coded double quote.

Namespace's `asXML()` also wrote the URI unescaped. It now escapes it. (It has no output format to take a quote character from, so it keeps using double quotes.)

Fixes dom4j#107
@guusdk
guusdk commented Oct 2, 2026
Copy link
Copy Markdown
Author

If this fix gets accepted I'd appreciate it being backported to a release on the 2.1 branch (our project cannot make the migration from JavaEE to Jakarta EE)

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Namespace URI is not encoded

1 participant

0