Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #2269: apoc.load procedures don't work anymore with urls containing % #2740

Merged
merged 1 commit into from
May 3, 2022
Merged
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
14 changes: 3 additions & 11 deletions core/src/main/java/apoc/util/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import static apoc.ApocConfig.apocConfig;
import static apoc.util.Util.ERROR_BYTES_OR_STRING;
import static apoc.util.Util.readHttpInputStream;
import static org.eclipse.jetty.util.URIUtil.encodePath;

/**
* @author mh
Expand Down Expand Up @@ -172,15 +171,13 @@ public static CountingInputStream inputStreamFor(Object input, Map<String, Objec
throw new RuntimeException(ERROR_BYTES_OR_STRING);
}
}

public static String changeFileUrlIfImportDirectoryConstrained(String urlNotEncoded) throws IOException {
final String url = encodeExceptQM(urlNotEncoded);


public static String changeFileUrlIfImportDirectoryConstrained(String url) throws IOException {
if (isFile(url) && isImportUsingNeo4jConfig()) {
if (!apocConfig().getBoolean(APOC_IMPORT_FILE_ALLOW__READ__FROM__FILESYSTEM)) {
throw new RuntimeException(String.format(ERROR_READ_FROM_FS_NOT_ALLOWED, url));
}
final Path resolvedPath = resolvePath(urlNotEncoded);
final Path resolvedPath = resolvePath(url);
return resolvedPath
.normalize()
.toUri()
Expand Down Expand Up @@ -349,11 +346,6 @@ public static Path getPathFromUrlString(String urlDir) {
return Paths.get(URI.create(urlDir));
}

// to exclude cases like 'testload.tar.gz?raw=true'
private static String encodeExceptQM(String url) {
return encodePath(url).replace("%3F", "?");
}

public static CountingInputStream getInputStreamFromBinary(byte[] urlOrBinary, String compressionAlgo) {
return CompressionAlgo.valueOf(compressionAlgo).toInputStream(urlOrBinary);
}
Expand Down