Skip to content

Commit 8f33f75

Browse files
committed
Fix handling different file URLs "file:/" and "file://"
1 parent ac01e35 commit 8f33f75

3 files changed

Lines changed: 18 additions & 6 deletions

File tree

flexmark-test-util/src/main/java/com/vladsch/flexmark/test/util/TestUtils.java

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@ public class TestUtils {
7676
final public static DataKey<Collection<Extension>> LOAD_EXTENSIONS = LoadUnloadDataKeyAggregator.LOAD_EXTENSIONS;
7777
final private static DataHolder EMPTY_OPTIONS = new DataSet();
7878
final public static DataKey<BiFunction<String, String, DataHolder>> CUSTOM_OPTION = new DataKey<>("CUSTOM_OPTION", (option, params) -> EMPTY_OPTIONS);
79-
final public static String FILE_PROTOCOL = ResourceUrlResolver.FILE_PROTOCOL;
79+
final public static String FILE_PROTOCOL_SINGLE_SLASH = ResourceUrlResolver.FILE_PROTOCOL_SINGLE_SLASH;
80+
final public static String FILE_PROTOCOL_DOUBLE_SLASH = ResourceUrlResolver.FILE_PROTOCOL_DOUBLE_SLASH;
8081

8182
public static DataHolder processOption(@NotNull Map<String, ? extends DataHolder> optionsMap, @NotNull String option) {
8283
DataHolder dataHolder = null;
@@ -612,7 +613,13 @@ public static DataHolder[] dataHolders(@Nullable DataHolder other, @Nullable Dat
612613
public static String getTestResourceRootDirectoryForModule(@NotNull Class<?> resourceClass, @NotNull String moduleRootPackage) {
613614
String fileUrl;
614615
fileUrl = getSpecResourceFileUrl(resourceClass, wrapWith(moduleRootPackage, "/", ".txt"));
615-
return removePrefix(removeSuffix(fileUrl, suffixWith(moduleRootPackage, ".txt")), FILE_PROTOCOL);
616+
fileUrl = removeSuffix(fileUrl, suffixWith(moduleRootPackage, ".txt"));
617+
if (fileUrl.startsWith(FILE_PROTOCOL_DOUBLE_SLASH)) {
618+
fileUrl = removePrefix(fileUrl, FILE_PROTOCOL_DOUBLE_SLASH);
619+
} else if (fileUrl.startsWith(FILE_PROTOCOL_SINGLE_SLASH)) {
620+
fileUrl = removePrefix(fileUrl, FILE_PROTOCOL_SINGLE_SLASH);
621+
}
622+
return fileUrl;
616623
}
617624

618625
@NotNull
@@ -623,7 +630,11 @@ public static String getRootDirectoryForModule(@NotNull Class<?> resourceClass,
623630
if (pos != -1) {
624631
fileUrl = fileUrl.substring(0, pos);
625632
}
626-
fileUrl = fileUrl.substring(FILE_PROTOCOL.length());
633+
if (fileUrl.startsWith(FILE_PROTOCOL_DOUBLE_SLASH)) {
634+
fileUrl = fileUrl.substring(FILE_PROTOCOL_DOUBLE_SLASH.length());
635+
} else if (fileUrl.startsWith(FILE_PROTOCOL_SINGLE_SLASH)) {
636+
fileUrl = fileUrl.substring(FILE_PROTOCOL_SINGLE_SLASH.length());
637+
}
627638
return fileUrl;
628639
}
629640

flexmark-test-util/src/main/java/com/vladsch/flexmark/test/util/spec/ResourceResolverManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public static String adjustedFileUrl(@NotNull URL url) {
3535
} else {
3636
File file = new File(filePath);
3737
if (file.exists()) {
38-
return TestUtils.FILE_PROTOCOL + filePath;
38+
return TestUtils.FILE_PROTOCOL_DOUBLE_SLASH + filePath;
3939
}
4040
}
4141
}

flexmark-test-util/src/main/java/com/vladsch/flexmark/test/util/spec/ResourceUrlResolver.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ public interface ResourceUrlResolver extends Function<String, String> {
1111
@Override
1212
String apply(String externalForm);
1313

14-
String FILE_PROTOCOL = "file://";
14+
String FILE_PROTOCOL_SINGLE_SLASH = "file:/";
15+
String FILE_PROTOCOL_DOUBLE_SLASH = FILE_PROTOCOL_SINGLE_SLASH + "/";
1516

1617
static boolean isFileProtocol(@NotNull String externalForm) {
17-
return externalForm.startsWith("file:/");
18+
return externalForm.startsWith(FILE_PROTOCOL_SINGLE_SLASH);
1819
}
1920

2021
static boolean hasProtocol(@NotNull String externalForm) {

0 commit comments

Comments
 (0)