fix overrun error reading invalid xhtml + fix loading problem on validation test

This commit is contained in:
Grahame Grieve 2021-05-13 22:51:01 +10:00
parent 9a82457b36
commit 3cb51f88c8
3 changed files with 36 additions and 3 deletions

View File

@ -871,10 +871,20 @@ private boolean elementIsOk(String name) throws FHIRFormatError {
return s.toString();
}
private String readUntil(String sc) throws IOException
{
StringBuilder s = new StringBuilder();
while (peekChar() != 0 && sc.indexOf(peekChar()) == -1)
s.append(readChar());
readChar();
return s.toString();
}
private void parseLiteral(StringBuilder s) throws IOException, FHIRFormatError {
// UInt16 w;
readChar();
String c = readUntil(';');
String c = readUntil(";&'\"><");
if (c.equals("apos"))
s.append('\'');
else if (c.equals("quot"))
@ -1162,8 +1172,12 @@ private boolean elementIsOk(String name) throws FHIRFormatError {
s.append((char) 201D);
else if (entities.containsKey(c))
s.append(entities.get(c));
else
else if (!mustBeWellFormed) {
// we guess that this is an accidentally unescaped &
s.append("&"+c);
} else {
throw new FHIRFormatError("unable to parse character reference '" + c + "'' (last text = '" + lastText + "'" + descLoc());
}
}
private boolean isInteger(String s, int base) {

View File

@ -1,5 +1,6 @@
package org.hl7.fhir.utilities.tests;
import org.hl7.fhir.exceptions.FHIRException;
import org.hl7.fhir.exceptions.FHIRFormatError;
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
import org.hl7.fhir.utilities.xhtml.XhtmlParser;
@ -94,5 +95,18 @@ public class XhtmlNodeTest {
@Test
public void testParseBadChars() throws FHIRFormatError, IOException {
XhtmlNode x = new XhtmlParser().parse(BaseTestingUtilities.loadTestResource("xhtml", "bad-chars.html"), "div");
}
@Test
public void testParseBadLink1() throws FHIRFormatError, IOException {
XhtmlNode x = new XhtmlParser().setMustBeWellFormed(false).parse(BaseTestingUtilities.loadTestResource("xhtml", "bad-link.html"), "div");
}
@Test
public void testParseBadLink2() throws FHIRFormatError, IOException {
Assertions.assertThrows(FHIRException.class, () -> new XhtmlParser().parse(BaseTestingUtilities.loadTestResource("xhtml", "bad-link.html"), "div"));
}
}

View File

@ -33,6 +33,7 @@ import org.hl7.fhir.r5.comparison.ProfileComparer.ProfileComparison;
import org.hl7.fhir.r5.comparison.ValueSetComparer;
import org.hl7.fhir.r5.comparison.ValueSetComparer.ValueSetComparison;
import org.hl7.fhir.r5.conformance.ProfileUtilities;
import org.hl7.fhir.r5.context.BaseWorkerContext;
import org.hl7.fhir.r5.context.IWorkerContext;
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
import org.hl7.fhir.r5.formats.JsonParser;
@ -109,7 +110,11 @@ public class ComparisonTests {
context = TestingUtilities.context();
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
NpmPackage npm = pcm.loadPackage("hl7.fhir.us.core#3.1.0");
context.loadFromPackage(npm, new R4ToR5Loader(new String[] { "CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire","ConceptMap","StructureMap", "NamingSystem"}, new NullLoaderKnowledgeProvider()));
BaseWorkerContext bc = (BaseWorkerContext) context;
boolean dupl = bc.isAllowLoadingDuplicates();
bc.setAllowLoadingDuplicates(true);
context.loadFromPackage(npm, new R4ToR5Loader(new String[] { "CapabilityStatement", "StructureDefinition", "ValueSet", "CodeSystem", "SearchParameter", "OperationDefinition", "Questionnaire","ConceptMap","StructureMap", "NamingSystem"}, new NullLoaderKnowledgeProvider()));
bc.setAllowLoadingDuplicates(dupl);
}
if (!new File(Utilities.path("[tmp]", "comparison")).exists()) {