Skip to content

Commit 9b7ab38

Browse files
author
Oleksandr Dzhychko
authored
Merge pull request #603 from drik98/bugfix/encode-branch-name-repo-overview
fix(model-server): Escape slashes in path segments in repository overview
2 parents 33cc83f + 209f3b5 commit 9b7ab38

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

model-server/src/main/kotlin/org/modelix/model/server/handlers/RepositoryOverview.kt

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -83,18 +83,10 @@ class RepositoryOverview(private val repoManager: RepositoriesManager) {
8383
buildHistoryLink(branch.repositoryId.id, branch.branchName)
8484
}
8585
td {
86-
a("../content/$repository/${branch.branchName}/latest/") {
87-
+"Explore Latest Version"
88-
}
86+
buildExploreLatestLink(branch.repositoryId.id, branch.branchName)
8987
}
9088
td {
91-
form {
92-
postButton {
93-
name = "delete"
94-
formAction = "../v2/repositories/${branch.repositoryId.id}/delete"
95-
+"Delete Repository"
96-
}
97-
}
89+
buildDeleteForm(branch.repositoryId.id)
9890
}
9991
}
10092
}
@@ -111,3 +103,19 @@ fun FlowOrInteractiveOrPhrasingContent.buildHistoryLink(repositoryId: String, br
111103
+"Show History"
112104
}
113105
}
106+
107+
fun FlowOrInteractiveOrPhrasingContent.buildExploreLatestLink(repositoryId: String, branchName: String) {
108+
a("../content/${repositoryId.encodeURLPathPart()}/${branchName.encodeURLPathPart()}/latest/") {
109+
+"Explore Latest Version"
110+
}
111+
}
112+
113+
fun FlowContent.buildDeleteForm(repositoryId: String) {
114+
form {
115+
postButton {
116+
name = "delete"
117+
formAction = "../v2/repositories/${repositoryId.encodeURLPathPart()}/delete"
118+
+"Delete Repository"
119+
}
120+
}
121+
}

model-server/src/test/kotlin/org/modelix/model/server/handlers/RepositoryOverviewTest.kt

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,22 @@ class RepositoryOverviewTest {
2525

2626
@Test
2727
fun testSlashesInPathSegmentsFromRepositoryIdAndBranchId() {
28-
val html = createHTML().span {
28+
val html = createHTML(prettyPrint = false).span {
2929
buildHistoryLink("repository/v1", "branch/v2")
30+
buildExploreLatestLink("repository/v1", "branch/v2")
31+
buildDeleteForm("repository/v1")
3032
}
31-
assertEquals("<span><a href=\"../history/repository%2Fv1/branch%2Fv2/\">Show History</a></span>", html)
33+
assertEquals(
34+
"""
35+
<span>
36+
<a href="../history/repository%2Fv1/branch%2Fv2/">Show History</a>
37+
<a href="../content/repository%2Fv1/branch%2Fv2/latest/">Explore Latest Version</a>
38+
<form>
39+
<button formmethod="post" name="delete" formaction="../v2/repositories/repository%2Fv1/delete">Delete Repository</button>
40+
</form>
41+
</span>
42+
""".lines().joinToString("") { it.trim() },
43+
html,
44+
)
3245
}
3346
}

0 commit comments

Comments
 (0)