From 7aae2cb5254a9dea0215274ddbbd138b271dd361 Mon Sep 17 00:00:00 2001 From: Grahame Grieve Date: Thu, 30 Jan 2025 00:53:09 +1100 Subject: [PATCH] fix bug parsing ")) { + s.append(readChar()); + } + String ss = s.toString(); + if (ss.length() >= 9) { + ss = ss.substring(0, ss.length()-9); + } + String t = isTrimWhitespace() ? ss.trim() : ss; + if (t.length() > 0) { + lastText = t; + node.addText(t).setLocation(markLocation()); + } + } + private void parseElement(XhtmlNode parent, List parents, NamespaceNormalizationMap namespaceMap) throws IOException, FHIRFormatError { markLocation(); @@ -676,9 +692,11 @@ public class XhtmlParser { throw new FHIRFormatError("unexpected non-end of element "+name+" "+descLoc()); readChar(); node.setEmptyExpanded(false); + } else if ("script".equals(name.getName())) { + parseScriptInner(node); } else { node.setEmptyExpanded(true); - parseElementInner(node, newParents, namespaceMap, "script".equals(name.getName())); + parseElementInner(node, newParents, namespaceMap); } } @@ -1341,7 +1359,7 @@ public class XhtmlParser { result.setName(n); unwindPoint = null; List p = new ArrayList<>(); - parseElementInner(result, p, null, true); + parseElementInner(result, p, null); return result; } diff --git a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/xhtml/XhtmlTests.java b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/xhtml/XhtmlTests.java index 7103bc418..d611587bf 100644 --- a/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/xhtml/XhtmlTests.java +++ b/org.hl7.fhir.utilities/src/test/java/org/hl7/fhir/utilities/xhtml/XhtmlTests.java @@ -1,11 +1,38 @@ package org.hl7.fhir.utilities.xhtml; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.io.IOException; + +import org.hl7.fhir.exceptions.FHIRFormatError; + public class XhtmlTests { + private static final String SOURCE_SCRIPT = + "\r\n"+ + "\r\n"+ + "\r\n"+ + " \r\n"+ + " This\r\n"+ + " \r\n"+ + " \r\n"+ + " \r\n"+ + " \r\n"+ + "\r\n"+ + " \r\n"+ + "\r\n"; + @Test public void testToStringOnNullType() { @@ -13,4 +40,10 @@ public class XhtmlTests { String actual = node.toString(); assertTrue(actual.startsWith("org.hl7.fhir.utilities.xhtml.XhtmlNode@"), "toString() should return java the toString default method for objects, which starts with the full class name"); } + + @Test + public void testParseScript() throws FHIRFormatError, IOException { + XhtmlNode x = new XhtmlParser().setMustBeWellFormed(true).parse(SOURCE_SCRIPT, "html"); + Assertions.assertTrue(x != null); + } }