Skip to content

Commit

Permalink
Fixes for Windows file separators.
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbrowndotje committed Sep 18, 2024
1 parent 71de823 commit 3c83773
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public PrefixSourceUrlStrategy(String prefix) {

@Override
public String urlOf(Type type) {
return prefix + type.getSource();
return prefix + (type.getSource().replaceAll("\\\\", "/"));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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));
}

}

0 comments on commit 3c83773

Please sign in to comment.