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
@@ -1,5 +1,6 @@
package com.datadog.debugger.symbol;

import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Path;
Expand Down Expand Up @@ -65,6 +66,13 @@ public static String trimPrefixes(String classFilePath) {
private static Path getPathFromPrefixedFileName(String locationStr, String prefix, int endIdx) {
String fileName = locationStr.substring(prefix.length(), endIdx);
LOGGER.debug("jar filename={}", fileName);
return Paths.get(fileName);
try {
// Reconstruct a file URI and use Paths.get(URI) to correctly handle
// platform-specific paths, including Windows drive letters (e.g. /C:/...)
return Paths.get(new URI("file:" + fileName));
} catch (URISyntaxException e) {
LOGGER.debug("Failed to parse as URI: {}, falling back to direct path", fileName, e);
return Paths.get(fileName);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Path;
import java.security.CodeSource;
import java.security.ProtectionDomain;
import java.security.cert.Certificate;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.EnabledOnOs;
import org.junit.jupiter.api.condition.OS;

class JarScannerTest {
@Test
Expand Down Expand Up @@ -50,4 +53,29 @@ public void extractJarPathFromNestedJar() throws URISyntaxException {
assertEquals(
jarFileUrl.getFile(), JarScanner.extractJarPath(protectionDomain, null).toString());
}

@Test
@EnabledOnOs(OS.WINDOWS)
public void extractJarPathFromFileOnWindows() throws URISyntaxException {
URL mockLocation = mock(URL.class);
when(mockLocation.toString())
.thenReturn("file:/C:/ColdFusion2016/cfusion/stubs/WS_831117134_1/");
CodeSource codeSource = new CodeSource(mockLocation, (Certificate[]) null);
ProtectionDomain protectionDomain = new ProtectionDomain(codeSource, null);
Path result = JarScanner.extractJarPath(protectionDomain, SymDBReport.NO_OP);
assertNotNull(result);
assertTrue(result.toString().contains("ColdFusion2016"));
}

@Test
@EnabledOnOs(OS.WINDOWS)
public void extractJarPathFromJarOnWindows() throws URISyntaxException {
URL mockLocation = mock(URL.class);
when(mockLocation.toString()).thenReturn("jar:file:/C:/libs/app.jar!/com/example/");
CodeSource codeSource = new CodeSource(mockLocation, (Certificate[]) null);
ProtectionDomain protectionDomain = new ProtectionDomain(codeSource, null);
Path result = JarScanner.extractJarPath(protectionDomain, SymDBReport.NO_OP);
assertNotNull(result);
assertTrue(result.toString().contains("app.jar"));
}
}
Loading