Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.eclipse.lemminx.uriresolver;

public class CacheResourceFileNotFoundException extends CacheResourceException {

public CacheResourceFileNotFoundException(String resourceURI, String message) {
super(resourceURI, message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

import static org.eclipse.lemminx.utils.ExceptionUtils.getRootCause;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -26,6 +27,7 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.text.MessageFormat;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -165,6 +167,16 @@ public Path getResource(final String resourceURI) throws IOException {
CacheResourceDownloadingError.DOWNLOAD_DISABLED, null, null);
}

URI resourceUriParsed = URI.create(resourceURI);
if ("file".equals(resourceUriParsed.getScheme())) {
// UNC path
Path path = Path.of(resourceUriParsed);
if (!Files.exists(path)) {
throw new CacheResourceFileNotFoundException(path.toString(), "The network-accessible file '" + path.toString() + "' doesn't exist");
}
return path;
}

if (!FilesUtils.isIncludedInDeployedPath(resourceCachePath)) {
throw new CacheResourceDownloadingException(resourceURI, resourceCachePath,
CacheResourceDownloadingError.RESOURCE_NOT_IN_DEPLOYED_PATH, null, null);
Expand Down Expand Up @@ -309,6 +321,7 @@ public static Path getResourceCachePath(String resourceURI) throws IOException {
}

public static Path getResourceCachePath(URI uri) throws IOException {

// Eliminate all path traversals
URI normalizedUri = uri.normalize();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,31 @@ public void schemaLocationDownloadDisabledUNC() throws Exception {
fileURI)));
}

@Test
public void schemaLocationFileDoesntExistUNC() throws Exception {

XMLValidationRootSettings validation = new XMLValidationRootSettings();
validation.setResolveExternalEntities(true);

XMLLanguageService ls = new XMLLanguageService();
ls.initializeIfNeeded();

String xml = "<?xml-model href=\"\\\\myserver\\myshare\\schema.xsd\"?>\r\n" + //
"<root-element>\r\n" + //
" \r\n" + //
"</root-element>\r\n";

String fileURI = "test.xml";

Diagnostic d = new Diagnostic(r(0, 18, 0, 47), "The network-accessible file '\\\\myserver\\myshare\\schema.xsd' doesn't exist",
DiagnosticSeverity.Error, "xml", XMLSchemaErrorCode.schema_reference_4.getCode());

// Test diagnostics
XMLAssert.testPublishDiagnosticsFor(xml, fileURI, validation, ls, pd(fileURI, d, //
new Diagnostic(r(1, 1, 1, 13), "cvc-elt.1.a: Cannot find the declaration of element 'root-element'.",
DiagnosticSeverity.Error, "xml", XMLSchemaErrorCode.cvc_elt_1_a.getCode())));
}

@Test
public void schemaLocationDownloadDisabledUNC2() throws Exception {

Expand Down
Loading