diff --git a/structurizr-component/src/main/java/com/structurizr/component/url/PrefixSourceUrlStrategy.java b/structurizr-component/src/main/java/com/structurizr/component/url/PrefixSourceUrlStrategy.java index 6419161d..1fd3047d 100644 --- a/structurizr-component/src/main/java/com/structurizr/component/url/PrefixSourceUrlStrategy.java +++ b/structurizr-component/src/main/java/com/structurizr/component/url/PrefixSourceUrlStrategy.java @@ -24,7 +24,7 @@ public PrefixSourceUrlStrategy(String prefix) { @Override public String urlOf(Type type) { - return prefix + type.getSource(); + return prefix + (type.getSource().replaceAll("\\\\", "/")); } @Override diff --git a/structurizr-component/src/test/java/com/structurizr/component/url/PrefixSourceUrlStrategyTests.java b/structurizr-component/src/test/java/com/structurizr/component/url/PrefixSourceUrlStrategyTests.java new file mode 100644 index 00000000..d4de1065 --- /dev/null +++ b/structurizr-component/src/test/java/com/structurizr/component/url/PrefixSourceUrlStrategyTests.java @@ -0,0 +1,26 @@ +package com.structurizr.component.url; + +import com.structurizr.component.Type; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +public class PrefixSourceUrlStrategyTests { + + @Test + void test_urlOf_WhenTheSourceUsesForwardSlashFileSeparators() { + Type type = new Type("com.example.ClassName"); + type.setSource("com/example/ClassName.java"); + + assertEquals("https://example.com/src/main/java/com/example/ClassName.java", new PrefixSourceUrlStrategy("https://example.com/src/main/java").urlOf(type)); + } + + @Test + void test_urlOf_WhenTheSourceUsesBackslashFileSeparators() { + Type type = new Type("com.example.ClassName"); + type.setSource("com\\example\\ClassName.java"); + + assertEquals("https://example.com/src/main/java/com/example/ClassName.java", new PrefixSourceUrlStrategy("https://example.com/src/main/java").urlOf(type)); + } + +} \ No newline at end of file