Skip to content

Fix invalid XML for emoji and math symbols in DocBook export - #17765

Merged
Siedlerchr merged 15 commits into
JabRef:mainfrom
cmarqueslau:fix-17747
Nov 10, 2026
Merged

Siedlerchr merged 15 commits into
JabRef:mainfrom
cmarqueslau:fix-17747

Conversation

@cmarqueslau

Copy link
Copy Markdown
Contributor

Summary

When an entry contains emoji or some math symbols the DocBook exports created invalid XML, so XML parsers could not read the file.

The reason is that XMLChars read the text one UTF-16 char at a time. These characters use two chars, so each half was written as a separate character reference. Now the formatter reads the text by Unicode code point, so each character becomes one valid reference. Other characters are escaped as before.

Steps to test

  1. Start JabRef and create a new library.
  2. Add an entry of type "Article" with the title "Smile 😀 and alpha 𝛼 and é".
  3. Select File -> Export -> Export all entries, choose DocBook 5.1 and save the file with the .xml extension.
  4. Open the file in a web browser. The browser should show the XML tree with the title "Smile 😀 and alpha 𝛼 and é".

How it is know:

image

How it was before:

image

Related issues and pull requests

Closes #17747

AI usage

I used Claude Code (model claude-opus-5-5) as an assistant. It helped me understand why surrogate pairs created invalid XML and suggested the code change. I reviewed and adjusted the code, wrote the steps to test, and ran the tests and the manual export myself.

Checklist

  • I own the copyright of the code submitted and I license it under the MIT license
  • If AI tools were used, I disclosed them in the "AI usage" section and reviewed, understood, and take full ownership of all AI-generated code
  • I manually tested my changes in running JabRef (always required)
  • I added JUnit tests for changes (if applicable)
  • I added screenshots in the PR description (if change is visible to the user)
  • I added one sentence (max 20 words) to CHANGELOG.md describing the change from the user's point of view (if the change is visible to the user)
  • [/] I checked the user documentation for up to dateness and submitted a pull request to our user documentation repository

@jabref-machine jabref-machine added the dev: send-to-black-forest Port to the black-forest branch of JabRef/jabref-black-forest after merging (ADR-0073) label Nov 9, 2026
@qodo-free-for-open-source-projects

Copy link
Copy Markdown
Contributor

PR Summary by Qodo

Fix invalid XML for emoji and math symbols in DocBook exports

🐞 Bug fix 🧪 Tests 🕐 10-20 Minutes

Grey Divider

AI Description

• Encode supplementary Unicode characters as single XML references so DocBook exports remain
 parseable.
• Add formatter and XML parsing tests for emoji, math symbols, and existing escaping behavior.
• Document the user-visible fix in the changelog.
Diagram

graph TD
  A["Entry text"] --> B["Code point scan"] --> C["XML references"] --> D["DocBook output"] --> E["XML parser"]
Loading
High-Level Assessment

Keep code-point iteration in the existing XMLChars formatter: it fixes surrogate-pair handling at the point shared by DocBook layouts while preserving the existing escaping rules. Manually combining surrogate pairs would add complexity without a clear benefit.

Files changed (3) +61 / -4

Bug fix (1) +6 / -4
XMLChars.javaEscape complete Unicode code points +6/-4

Escape complete Unicode code points

• Replaces UTF-16 character iteration with code-point iteration and advances by each code point's character count. Supplementary symbols now produce one XML reference instead of separate references for their surrogate halves.

jablib/src/main/java/org/jabref/logic/layout/format/XMLChars.java

Tests (1) +54 / -0
XMLCharsTest.javaTest Unicode escaping and XML parseability +54/-0

Test Unicode escaping and XML parseability

• Adds parameterized assertions for existing escaping and supplementary Unicode output. Parses formatted text as XML and checks that its text content matches the input.

jablib/src/test/java/org/jabref/logic/layout/format/XMLCharsTest.java

Documentation (1) +1 / -0
CHANGELOG.mdDocument the DocBook XML export fix +1/-0

Document the DocBook XML export fix

• Adds a user-facing note that emoji and some math symbols no longer cause invalid DocBook XML.

CHANGELOG.md

@github-actions github-actions Bot added the component: unicode unicode related issues label Nov 9, 2026
@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0)

Grey Divider

Great, no issues found!

Qodo reviewed your code and found no material issues that require review

Grey Divider

Tip of the day
💡 Did you know, you can move or hide resolved findings to focus on what still needs action

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@github-actions github-actions Bot added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Nov 9, 2026
@Gautam-aman

Copy link
Copy Markdown
Contributor

The code-point iteration looks correct and fixes the surrogate-pair issue. One suggestion: could we add an integration test that generates a complete DocBook 4 or 5.1 export containing supplementary Unicode characters and validates the resulting XML? The current tests only parse a standalone <title> element, so they don't verify the full export pipeline or DocBook schema validity.

@github-actions github-actions Bot removed the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Nov 10, 2026
@cmarqueslau

cmarqueslau commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor Author

The code-point iteration looks correct and fixes the surrogate-pair issue. One suggestion: could we add an integration test that generates a complete DocBook 4 or 5.1 export containing supplementary Unicode characters and validates the resulting XML? The current tests only parse a standalone <title> element, so they don't verify the full export pipeline or DocBook schema validity.

I added a new test that runs the full DocBook 5.1 pipeline and checks that the output is well-formed XML and characters are preserved correctly. Schema validation would require a new dependency and may reveal layout issues, so I'd suggest handling that in a separate issue if needed.

@Gautam-aman, @Siedlerchr

@github-actions github-actions Bot added the status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers label Nov 10, 2026

@Siedlerchr Siedlerchr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, schema validation can be done in a new issue

@Siedlerchr
Siedlerchr added this pull request to the merge queue Nov 10, 2026
@github-actions github-actions Bot added status: to-be-merged PRs which are accepted and should go into the merge-queue. and removed status: ready-for-review Pull Requests that are ready to be reviewed by the maintainers labels Nov 10, 2026
Merged via the queue into JabRef:main with commit 61dcea6 Nov 10, 2026
77 checks passed
@jabref-machine

Copy link
Copy Markdown
Collaborator

Siedlerchr added a commit to Siedlerchr/jabref that referenced this pull request Nov 11, 2026
* main: (90 commits)
  Chore(deps): Bump jablib/src/main/resources/csl-styles from `3220666` to `af0aea3` (JabRef#17788)
  Chore(deps): Bump us.hebi.graalvm:jfx-static-libs from 27-2 to 27.0.1 in /versions (JabRef#17796)
  chore(deps): update dependency org.bouncycastle:bcprov-jdk18on to v1.87 (JabRef#17794)
  Chore(deps): Bump actions/setup-java from 6.1.0 to 6.2.0 in /.github/actions/setup-gradle (JabRef#17795)
  Chore(deps): Bump actions/setup-java from 6.1.0 to 6.2.0 (JabRef#17792)
  Chore(deps): Bump docker/login-action from 4.7.0 to 4.8.0 (JabRef#17791)
  Chore(deps): Bump peter-evans/create-pull-request from 8.1.1 to 8.1.3 (JabRef#17793)
  Chore(deps): Bump anthropics/claude-code-action from 1.0.264 to 1.0.271 (JabRef#17790)
  Chore(deps): Bump ruby/setup-ruby from 1.336.0 to 1.338.0 (JabRef#17789)
  New Crowdin updates (JabRef#17785)
  Add "No value" subgroup to automatic keyword groups (JabRef#17716)
  Fix invalid XML for emoji and math symbols in DocBook export (JabRef#17765)
  Fix RTF export when formatting ends a field (JabRef#17766)
  Chore(deps): Bump com.autonomousapps:dependency-analysis-gradle-plugin from 3.20.1 to 3.20.2 in /build-logic (JabRef#17770)
  Chore(deps): Bump com.autonomousapps:dependency-analysis-gradle-plugin from 3.20.1 to 3.20.2 (JabRef#17769)
  New Crowdin updates (JabRef#17768)
  Diagnose stalled GUI tests and align dependency versions (JabRef#17763)
  Keep entry table still while a search match is in view (JabRef#16905)
  Add BibSonomy as a web search fetcher (JabRef#17611)
  Chore(deps): Bump com.konghq:unirest-modules-gson from 4.11.3 to 4.11.4 in /versions (JabRef#17761)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

component: export-or-save component: unicode unicode related issues dev: send-to-black-forest Port to the black-forest branch of JabRef/jabref-black-forest after merging (ADR-0073) size: small status: to-be-merged PRs which are accepted and should go into the merge-queue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

XMLChars produces invalid XML for supplementary Unicode characters used in DocBook exports

5 participants