8000 Fixes glob matching on Windows by bbakerman · Pull Request #2513 · graphql-java/graphql-java · GitHub
[go: up one dir, main page]

Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import graphql.Internal;
import graphql.normalized.ExecutableNormalizedField;

import java.io.File;
import java.nio.file.FileSystems;
import java.nio.file.Path;
import java.nio.file.PathMatcher;
Expand All @@ -30,6 +31,7 @@
public class DataFetchingFieldSelectionSetImpl implements DataFetchingFieldSelectionSet {

private final static String SEP = "/";
private final static boolean UNIXY = SEP.equals(File.separator);

private final static DataFetchingFieldSelectionSet NOOP = new DataFetchingFieldSelectionSet() {

Expand Down Expand Up @@ -110,6 +112,7 @@ public boolean contains(String fieldGlobPattern) {
fieldGlobPattern = removeLeadingSlash(fieldGlobPattern);
PathMatcher globMatcher = globMatcher(fieldGlobPattern);
for (String flattenedField : flattenedFieldsForGlobSearching) {
flattenedField = osAppropriate(flattenedField);
Path path = Paths.get(flattenedField);
if (globMatcher.matches(path)) {
return true;
Expand All @@ -118,6 +121,14 @@ public boolean contains(String fieldGlobPattern) {
return false;
}

private String osAppropriate(String flattenedField) {
if (UNIXY) {
return flattenedField;
} else {
return flattenedField.replace(SEP, "\\");
}
}

@Override
public boolean containsAnyOf(String fieldGlobPattern, String... fieldGlobPatterns) {
assertNotNull(fieldGlobPattern);
Expand Down
0