Skip to content
Merged
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
Expand Up @@ -86,10 +86,15 @@ static String extractSourceName(String source) {
if (source == null || source.isBlank()) {
return null;
}
// strip scheme prefix (e.g. "file:")
int colon = source.lastIndexOf(':');
if (colon >= 0 && colon < source.length() - 1) {
source = source.substring(colon + 1);
// strip URI scheme prefix (e.g. "file:", "classpath:") — only if the part
// before the first colon is all letters (a valid scheme). This avoids
// stripping line numbers from sources like "cheese.java:9".
int colon = source.indexOf(':');
if (colon > 0) {
String scheme = source.substring(0, colon);
if (scheme.chars().allMatch(Character::isLetter)) {
source = source.substring(colon + 1);
}
}
// return just the filename part
int slash = Math.max(source.lastIndexOf('/'), source.lastIndexOf('\\'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -806,6 +806,46 @@ void testNodeTextPaddingScalesWithNodeWidth() {
"Text padding should increase with wider nodes");
}

@Test
void testExtractSourceNameWithScheme() {
assertEquals("my-route.yaml", RouteDiagramHelper.extractSourceName("file:/path/to/my-route.yaml"));
}

@Test
void testExtractSourceNameClasspath() {
assertEquals("my-route.yaml", RouteDiagramHelper.extractSourceName("classpath:my-route.yaml"));
}

@Test
void testExtractSourceNameWithLineNumber() {
assertEquals("cheese.java:9", RouteDiagramHelper.extractSourceName("cheese.java:9"));
}

@Test
void testExtractSourceNameSchemeAndLineNumber() {
assertEquals("cheese.java:9", RouteDiagramHelper.extractSourceName("file:/path/to/cheese.java:9"));
}

@Test
void testExtractSourceNamePlainFilename() {
assertEquals("my-route.yaml", RouteDiagramHelper.extractSourceName("my-route.yaml"));
}

@Test
void testExtractSourceNameWindowsPath() {
assertEquals("route.yaml", RouteDiagramHelper.extractSourceName("C:\\Users\\test\\route.yaml"));
}

@Test
void testExtractSourceNameNull() {
assertNull(RouteDiagramHelper.extractSourceName(null));
}

@Test
void testExtractSourceNameBlank() {
assertNull(RouteDiagramHelper.extractSourceName(""));
}

private static NodeInfo node(String type, String code, int level) {
return node(type, code, level, null);
}
Expand Down
Loading