Skip to content

Commit dc73a24

Browse files
committed
resolver: attempt to get a known System ID when the supplied System ID is unknown but the Public ID is known
1 parent 618c6ec commit dc73a24

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

junit/io/sf/carte/doc/xml/dtd/DefaultEntityResolverTest.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,19 @@ public void resolveEntityStringStringSVG10() throws SAXException, IOException {
161161
re.close();
162162
}
163163

164+
@Test
165+
public void resolveEntityStringStringSVG10_WrongSystemID() throws SAXException, IOException {
166+
InputSource isrc = resolver.resolveEntity("-//W3C//DTD SVG 1.0//EN",
167+
"http://www.w3.org/TR/SVG/DTD/svg10.dtd");
168+
assertNotNull(isrc);
169+
assertEquals("-//W3C//DTD SVG 1.0//EN", isrc.getPublicId());
170+
assertEquals("http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd",
171+
isrc.getSystemId());
172+
Reader re = isrc.getCharacterStream();
173+
assertNotNull(re);
174+
re.close();
175+
}
176+
164177
@Test
165178
public void resolveEntityStringStringRemoteDisallow() throws SAXException, IOException {
166179
assertThrows(SAXException.class,
@@ -171,7 +184,7 @@ public void resolveEntityStringStringRemoteDisallow() throws SAXException, IOExc
171184
@Test
172185
public void resolveEntityStringStringRemoteDisallowConstructor1Arg()
173186
throws SAXException, IOException {
174-
assertThrows(SAXException.class, () -> resolver.resolveEntity("-//W3C//DTD SVG 1.1//EN",
187+
assertThrows(SAXException.class, () -> resolver.resolveEntity("-//W3C//DTD SVG 0.9//EN",
175188
"https://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"));
176189
}
177190

src/io/sf/carte/doc/xml/dtd/DefaultEntityResolver.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,15 @@ public InputSource resolveEntity(String name, String publicId, String baseURI, S
492492
}
493493
String fname = systemIdToFilename.get(systemId);
494494

495+
if (fname == null && publicId != null) {
496+
// Attempt to get a known DTD by Public ID
497+
String knownSystemId = getSystemIdFromPublicId(publicId);
498+
if (knownSystemId != null) {
499+
fname = systemIdToFilename.get(knownSystemId);
500+
systemId = knownSystemId;
501+
}
502+
}
503+
495504
InputSource isrc = null;
496505
if (fname != null) {
497506
Reader re = dtdLoader.loadDTDfromClasspath(loader, fname);

0 commit comments

Comments
 (0)