From b8e8e771f0fc860a0baac1b282b505d31f1f1cac Mon Sep 17 00:00:00 2001 From: Adrian Clay Date: Thu, 4 Jan 2024 16:29:05 +0000 Subject: [PATCH] Add support to XhtmlParser to handle 2 character HTML Entities Previously, the parser would mangle any HTML entity greater than 0xFFFF --- .../org/hl7/fhir/utilities/xhtml/XhtmlParser.java | 4 ++-- .../org/hl7/fhir/utilities/tests/XhtmlNodeTest.java | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlParser.java b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlParser.java index fa6e02545..f7db1cc7f 100644 --- a/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlParser.java +++ b/org.hl7.fhir.utilities/src/main/java/org/hl7/fhir/utilities/xhtml/XhtmlParser.java @@ -970,9 +970,9 @@ public class XhtmlParser { throw new FHIRFormatError("Invalid literal declaration following text: " + s); else if (c.charAt(0) == '#') { if (isInteger(c.substring(1), 10)) - s.append((char) Integer.parseInt(c.substring(1))); + s.append(Character.toString(Integer.parseInt(c.substring(1)))); else if (c.charAt(1) == 'x' && isInteger(c.substring(2), 16)) - s.append((char) Integer.parseInt(c.substring(2), 16)); + s.append(Character.toString(Integer.parseInt(c.substring(2), 16))); } else if (declaredEntities.containsKey(c)) { s.append(declaredEntities.get(c)); } else { diff --git a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/tests/XhtmlNodeTest.java b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/tests/XhtmlNodeTest.java index 62f6ed1b4..114f087ce 100644 --- a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/tests/XhtmlNodeTest.java +++ b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/tests/XhtmlNodeTest.java @@ -207,5 +207,17 @@ public class XhtmlNodeTest { Assertions.assertEquals("

This is a long paragraph

", new XhtmlComposer(true, false).compose(x)); } + @Test + public void testEntityNumberGreaterThanFFFF_Decimal() throws IOException { + XhtmlNode x = new XhtmlParser().parse("
😷
", "div"); + Assertions.assertEquals("\uD83D\uDE37", x.getFirstElement().getChildNodes().get(0).getContent()); + } + + @Test + public void testEntityNumberGreaterThanFFFF_Hex() throws IOException { + XhtmlNode x = new XhtmlParser().parse("
😷
", "div"); + Assertions.assertEquals("\uD83D\uDE37", x.getFirstElement().getChildNodes().get(0).getContent()); + } + } \ No newline at end of file