Skip to content

Commit

Permalink
#1732: systemId resolution regression introduced in 2.3.4+
Browse files Browse the repository at this point in the history
Signed-off-by: Lukas Jungmann <[email protected]>
(cherry picked from commit 20c8ed3)
  • Loading branch information
lukasj committed Oct 13, 2023
1 parent b8201b4 commit e1bba23
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -40,8 +40,6 @@
import com.sun.xml.bind.unmarshaller.DOMScanner;
import com.sun.xml.bind.v2.util.XmlFactory;
import com.sun.xml.xsom.XSSchemaSet;
import java.nio.file.Files;
import java.nio.file.Paths;

import org.w3c.dom.Element;
import org.w3c.dom.ls.LSInput;
Expand Down Expand Up @@ -215,11 +213,9 @@ public LSInput resolveResource(String type, String namespaceURI, String publicId
// XSOM passes the namespace URI to the publicID parameter.
// we do the same here .
InputSource is = opts.entityResolver.resolveEntity(namespaceURI, systemId == null ? "" : systemId);
return isExists(is) ? new LSInputSAXWrapper(is) : null;
} catch (SAXException e) {
// TODO: is this sufficient?
return null;
} catch (IOException e) {
if (is == null) return null;
return new LSInputSAXWrapper(is);
} catch (SAXException | IOException e) {
// TODO: is this sufficient?
return null;
}
Expand Down Expand Up @@ -293,21 +289,6 @@ public void fatalError(SAXParseException exception) {
errorListener.fatalError(exception);
}

private static boolean isExists(InputSource is) {
if (is == null) {
return false;
}
try {
URI uri = new URI(is.getSystemId());
if ("file".equals(uri.getScheme())) {
return Files.exists(Paths.get(uri));
}
} catch (URISyntaxException ex) {
//ignore, let it be handled by parser as is
}
return true;
}

/**
* We use JAXP 1.3 to do a schema correctness check, but we know
* it doesn't always work. So in case some people hit the problem,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -43,10 +43,6 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.*;

import static com.sun.xml.bind.v2.util.XmlFactory.allowExternalAccess;
Expand Down Expand Up @@ -267,26 +263,13 @@ public Document parse( String systemId, boolean root ) throws SAXException, IOEx
InputSource is=null;

// allow entity resolver to find the actual byte stream.
if( entityResolver!=null ) {
is = entityResolver.resolveEntity(null,systemId);
if (entityResolver != null) {
is = entityResolver.resolveEntity(null, systemId);
}
if (is == null) {
is = new InputSource(systemId);
} else {
try {
URI uri = new URI(is.getSystemId());
if ("file".equals(uri.getScheme())) {
if (!Files.exists(Paths.get(uri))) {
//resolved file does not exist, warn and let's continue with original systemId
errorReceiver.warning(null, Messages.format(
Messages.DOMFOREST_CATALOG_INVALID_ENTRY, is.getSystemId(), systemId));
is = new InputSource(systemId);
}
}
} catch (URISyntaxException ex) {
//ignore, let it be handled by parser as is
}
}

// but we still use the original system Id as the key.
return parse( systemId, is, root );
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -66,7 +66,5 @@ static String format( String property, Object... args ) {
"ERR_GENERAL_SCHEMA_CORRECTNESS_ERROR";
static final String DOMFOREST_INPUTSOURCE_IOEXCEPTION = // arg:2
"DOMFOREST_INPUTSOURCE_IOEXCEPTION";
static final String DOMFOREST_CATALOG_INVALID_ENTRY = // arg:2
"DOMFOREST_CATALOG_INVALID_ENTRY";

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#
# Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
# Copyright (c) 1997, 2023 Oracle and/or its affiliates. All rights reserved.
#
# This program and the accompanying materials are made available under the
# terms of the Eclipse Distribution License v. 1.0, which is available at
Expand Down Expand Up @@ -88,6 +88,3 @@ ERR_FILENAME_IS_NOT_URI = \

DOMFOREST_INPUTSOURCE_IOEXCEPTION = \
IOException thrown when processing "{0}". Exception: {1}.

DOMFOREST_CATALOG_INVALID_ENTRY = \
Catalog points to non-existent resource: "{0}". Trying to reach "{1}" directly.

0 comments on commit e1bba23

Please sign in to comment.