fix overrun error reading invalid xhtml + fix loading problem on validation test
This commit is contained in:
parent
9a82457b36
commit
3cb51f88c8
|
@ -871,10 +871,20 @@ private boolean elementIsOk(String name) throws FHIRFormatError {
|
||||||
return s.toString();
|
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 {
|
private void parseLiteral(StringBuilder s) throws IOException, FHIRFormatError {
|
||||||
// UInt16 w;
|
// UInt16 w;
|
||||||
readChar();
|
readChar();
|
||||||
String c = readUntil(';');
|
String c = readUntil(";&'\"><");
|
||||||
if (c.equals("apos"))
|
if (c.equals("apos"))
|
||||||
s.append('\'');
|
s.append('\'');
|
||||||
else if (c.equals("quot"))
|
else if (c.equals("quot"))
|
||||||
|
@ -1162,9 +1172,13 @@ private boolean elementIsOk(String name) throws FHIRFormatError {
|
||||||
s.append((char) 201D);
|
s.append((char) 201D);
|
||||||
else if (entities.containsKey(c))
|
else if (entities.containsKey(c))
|
||||||
s.append(entities.get(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());
|
throw new FHIRFormatError("unable to parse character reference '" + c + "'' (last text = '" + lastText + "'" + descLoc());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isInteger(String s, int base) {
|
private boolean isInteger(String s, int base) {
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package org.hl7.fhir.utilities.tests;
|
package org.hl7.fhir.utilities.tests;
|
||||||
|
|
||||||
|
import org.hl7.fhir.exceptions.FHIRException;
|
||||||
import org.hl7.fhir.exceptions.FHIRFormatError;
|
import org.hl7.fhir.exceptions.FHIRFormatError;
|
||||||
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
import org.hl7.fhir.utilities.xhtml.XhtmlNode;
|
||||||
import org.hl7.fhir.utilities.xhtml.XhtmlParser;
|
import org.hl7.fhir.utilities.xhtml.XhtmlParser;
|
||||||
|
@ -95,4 +96,17 @@ public class XhtmlNodeTest {
|
||||||
public void testParseBadChars() throws FHIRFormatError, IOException {
|
public void testParseBadChars() throws FHIRFormatError, IOException {
|
||||||
XhtmlNode x = new XhtmlParser().parse(BaseTestingUtilities.loadTestResource("xhtml", "bad-chars.html"), "div");
|
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"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
|
@ -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;
|
||||||
import org.hl7.fhir.r5.comparison.ValueSetComparer.ValueSetComparison;
|
import org.hl7.fhir.r5.comparison.ValueSetComparer.ValueSetComparison;
|
||||||
import org.hl7.fhir.r5.conformance.ProfileUtilities;
|
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.context.IWorkerContext;
|
||||||
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
|
import org.hl7.fhir.r5.formats.IParser.OutputStyle;
|
||||||
import org.hl7.fhir.r5.formats.JsonParser;
|
import org.hl7.fhir.r5.formats.JsonParser;
|
||||||
|
@ -109,7 +110,11 @@ public class ComparisonTests {
|
||||||
context = TestingUtilities.context();
|
context = TestingUtilities.context();
|
||||||
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
|
FilesystemPackageCacheManager pcm = new FilesystemPackageCacheManager(true, ToolsVersion.TOOLS_VERSION);
|
||||||
NpmPackage npm = pcm.loadPackage("hl7.fhir.us.core#3.1.0");
|
NpmPackage npm = pcm.loadPackage("hl7.fhir.us.core#3.1.0");
|
||||||
|
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()));
|
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()) {
|
if (!new File(Utilities.path("[tmp]", "comparison")).exists()) {
|
||||||
|
|
Loading…
Reference in New Issue