From 7539c22f78f5e49b19acccb49b3fde4ece7cfdc1 Mon Sep 17 00:00:00 2001 From: Victor Levasseur Date: Thu, 18 Apr 2024 18:49:13 +0200 Subject: [PATCH] fix: the header branch selector now properly encode the branch name as an URI --- .../site/model/BranchHomeLinkViewModel.kt | 4 +++- .../site/model/BranchHomeLinkViewModelTest.kt | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/BranchHomeLinkViewModel.kt b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/BranchHomeLinkViewModel.kt index 3015fc34..3943afc3 100644 --- a/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/BranchHomeLinkViewModel.kt +++ b/src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/BranchHomeLinkViewModel.kt @@ -1,11 +1,13 @@ package nl.avisi.structurizr.site.generatr.site.model import nl.avisi.structurizr.site.generatr.site.asUrlToDirectory +import java.net.URLEncoder +import java.nio.charset.StandardCharsets data class BranchHomeLinkViewModel( private val pageViewModel: PageViewModel, private val branchName: String ) { val title get() = branchName - val relativeHref get() = HomePageViewModel.url().asUrlToDirectory(pageViewModel.url) + "../$branchName/" + val relativeHref get() = HomePageViewModel.url().asUrlToDirectory(pageViewModel.url) + "../${URLEncoder.encode(branchName, StandardCharsets.UTF_8)}/" } diff --git a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/BranchHomeLinkViewModelTest.kt b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/BranchHomeLinkViewModelTest.kt index cb010ffe..fff55d1f 100644 --- a/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/BranchHomeLinkViewModelTest.kt +++ b/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/BranchHomeLinkViewModelTest.kt @@ -29,4 +29,20 @@ class BranchHomeLinkViewModelTest : ViewModelTest() { assertThat(viewModel.relativeHref) .isEqualTo("./../master/") } + + @Test + fun `title is branch name when branch name contains slash`() { + val viewModel = BranchHomeLinkViewModel(pageViewModel(), "feat/branch-1") + + assertThat(viewModel.title) + .isEqualTo("feat/branch-1") + } + + @Test + fun `relative href from home when branch name contains slash`() { + val viewModel = BranchHomeLinkViewModel(pageViewModel("/"), "feat/branch-1") + + assertThat(viewModel.relativeHref) + .isEqualTo("./../feat%2Fbranch-1/") + } }