Skip to content

Commit

Permalink
Merge pull request #603 from drik98/bugfix/encode-branch-name-repo-ov…
Browse files Browse the repository at this point in the history
…erview

fix(model-server): Escape slashes in path segments in repository overview
  • Loading branch information
odzhychko authored Mar 14, 2024
2 parents 33cc83f + 209f3b5 commit 9b7ab38
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,10 @@ class RepositoryOverview(private val repoManager: RepositoriesManager) {
buildHistoryLink(branch.repositoryId.id, branch.branchName)
}
td {
a("../content/$repository/${branch.branchName}/latest/") {
+"Explore Latest Version"
}
buildExploreLatestLink(branch.repositoryId.id, branch.branchName)
}
td {
form {
postButton {
name = "delete"
formAction = "../v2/repositories/${branch.repositoryId.id}/delete"
+"Delete Repository"
}
}
buildDeleteForm(branch.repositoryId.id)
}
}
}
Expand All @@ -111,3 +103,19 @@ fun FlowOrInteractiveOrPhrasingContent.buildHistoryLink(repositoryId: String, br
+"Show History"
}
}

fun FlowOrInteractiveOrPhrasingContent.buildExploreLatestLink(repositoryId: String, branchName: String) {
a("../content/${repositoryId.encodeURLPathPart()}/${branchName.encodeURLPathPart()}/latest/") {
+"Explore Latest Version"
}
}

fun FlowContent.buildDeleteForm(repositoryId: String) {
form {
postButton {
name = "delete"
formAction = "../v2/repositories/${repositoryId.encodeURLPathPart()}/delete"
+"Delete Repository"
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,22 @@ class RepositoryOverviewTest {

@Test
fun testSlashesInPathSegmentsFromRepositoryIdAndBranchId() {
val html = createHTML().span {
val html = createHTML(prettyPrint = false).span {
buildHistoryLink("repository/v1", "branch/v2")
buildExploreLatestLink("repository/v1", "branch/v2")
buildDeleteForm("repository/v1")
}
assertEquals("<span><a href=\"../history/repository%2Fv1/branch%2Fv2/\">Show History</a></span>", html)
assertEquals(
"""
<span>
<a href="../history/repository%2Fv1/branch%2Fv2/">Show History</a>
<a href="../content/repository%2Fv1/branch%2Fv2/latest/">Explore Latest Version</a>
<form>
<button formmethod="post" name="delete" formaction="../v2/repositories/repository%2Fv1/delete">Delete Repository</button>
</form>
</span>
""".lines().joinToString("") { it.trim() },
html,
)
}
}

0 comments on commit 9b7ab38

Please sign in to comment.