From cf82025c0d8a6f77aa6ec8462675a00e278dc46f Mon Sep 17 00:00:00 2001 From: James Agnew Date: Tue, 7 Jan 2020 13:36:33 -0500 Subject: [PATCH] Correctly handle narratives where the XHTML namespace is bound to a dumb prefix --- .../hl7/fhir/utilities/xhtml/XhtmlParser.java | 5 +---- .../fhir/utilities/tests/XhtmlNodeTest.java | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 6 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 75442e02f..c65585f32 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 @@ -473,7 +473,7 @@ private boolean elementIsOk(String name) throws FHIRFormatError { readChar(); } else { unwindPoint = null; - List p = new ArrayList(); + List p = new ArrayList<>(); parseElementInner(root, p, nsm, true); } return result; @@ -489,9 +489,6 @@ private boolean elementIsOk(String name) throws FHIRFormatError { // what we do here is strip out any stated namespace attributes, putting them in the namesapce map // then we figure out what the namespace of this element is, and state it explicitly if it's not the default - // but we don't bother with any of this if we're not validating - if (!validatorMode) - return null; NSMap result = new NSMap(nsm); List nsattrs = new ArrayList(); for (String an : node.getAttributes().keySet()) { 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 bee8fe594..ced5e7935 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 @@ -2,11 +2,15 @@ package org.hl7.fhir.utilities.tests; import org.hl7.fhir.utilities.xhtml.XhtmlNode; import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import static org.junit.Assert.assertEquals; public class XhtmlNodeTest { + private static final Logger ourLog = LoggerFactory.getLogger(XhtmlNodeTest.class); + /** * See https://github.com/jamesagnew/hapi-fhir/issues/1488 */ @@ -36,7 +40,6 @@ public class XhtmlNodeTest { assertEquals("
help i'm a bug
", new XhtmlNode().setValue(dt.getValue()).getValueAsString()); } - @Test public void testParseRsquo() { XhtmlNode dt = new XhtmlNode(); @@ -45,7 +48,6 @@ public class XhtmlNodeTest { assertEquals("
It’s January again
", new XhtmlNode().setValue(dt.getValue()).getValueAsString()); } - @Test public void testProcessingInstructionNotPreserved() { XhtmlNode dt = new XhtmlNode(); @@ -54,6 +56,19 @@ public class XhtmlNodeTest { assertEquals("
help i'm a bug
", new XhtmlNode().setValue(dt.getValue()).getValueAsString()); } + @Test + public void testParseXhtmlQualified() { + XhtmlNode node = new XhtmlNode(); + node.setValueAsString("" + + "" + + "@fhirabend" + + ""); + + String output = node.getValueAsString(); + ourLog.info(output); + + assertEquals("
\"Twitter@fhirabend
", output); + } } \ No newline at end of file