Skip to content

Commit

Permalink
SOLR-15340: Fix wildcard path detection on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
bruno-roustant committed May 3, 2021
1 parent b27b587 commit 6c969f7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
24 changes: 21 additions & 3 deletions solr/core/src/java/org/apache/solr/core/SolrPaths.java
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,35 @@ public static void assertPathAllowed(Path pathToAssert, Set<Path> allowPaths) th

/**
* Builds a set of allowed {@link Path}.
* Detects special paths '*' and '_ALL_' that mean all paths are allowed.
* Detects special paths "*" and "_ALL_" that mean all paths are allowed.
*/
public static class AllowPathBuilder {

private static final Path WILDCARD_PATH = Paths.get("*");
private static final String WILDCARD_PATH = "*";

private Set<Path> paths;

/**
* Adds an allowed path.
* Detects "*" and "_ALL_" which mean all paths are allowed.
*/
public AllowPathBuilder addPath(String path) {
if (path.equals(WILDCARD_PATH)) {
paths = ALL_PATHS;
} else {
addPath(Paths.get(path));
}
return this;
}

/**
* Adds an allowed path.
* Detects "_ALL_" which means all paths are allowed.
* Does not detect "*" (not supported as a {@link Path} on Windows), see {@link #addPath(String)}.
*/
public AllowPathBuilder addPath(Path path) {
if (paths != ALL_PATHS) {
if (path.equals(ALL_PATH) || path.equals(WILDCARD_PATH)) {
if (path.equals(ALL_PATH)) {
paths = ALL_PATHS;
} else {
if (paths == null) {
Expand Down
3 changes: 1 addition & 2 deletions solr/core/src/java/org/apache/solr/core/SolrXmlConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -372,7 +371,7 @@ private static Set<Path> separatePaths(String commaSeparatedString) {
String[] pathStrings = COMMA_SEPARATED_PATTERN.split(commaSeparatedString);
SolrPaths.AllowPathBuilder allowPathBuilder = new SolrPaths.AllowPathBuilder();
for (String p : pathStrings) {
allowPathBuilder.addPath(Paths.get(p));
allowPathBuilder.addPath(p);
}
return allowPathBuilder.build();
}
Expand Down

0 comments on commit 6c969f7

Please sign in to comment.