Skip to content

Commit

Permalink
Fix spaces in file names
Browse files Browse the repository at this point in the history
  • Loading branch information
apardyl committed Nov 20, 2018
1 parent b018d80 commit 3549e27
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ apply plugin: 'io.spring.dependency-management'
apply plugin: 'io.gitlab.arturbosch.detekt'

group = 'pl.edu.uj.ii.ksi'
version = '0.0.3'
version = '0.0.5'
sourceCompatibility = 1.8

compileKotlin {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package pl.edu.uj.ii.ksi.mordor.controllers

import java.net.URI
import javax.servlet.http.HttpServletRequest
import javax.servlet.http.HttpServletResponse
import org.apache.commons.io.FileUtils
Expand All @@ -9,6 +8,7 @@ import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.servlet.ModelAndView
import org.springframework.web.servlet.view.RedirectView
import org.springframework.web.util.UriUtils
import pl.edu.uj.ii.ksi.mordor.exceptions.BadRequestException
import pl.edu.uj.ii.ksi.mordor.exceptions.NotFoundException
import pl.edu.uj.ii.ksi.mordor.services.IconNameProvider
Expand Down Expand Up @@ -43,14 +43,17 @@ class FilesystemController(
return pathBreadcrumb
}

private fun urlEncodePath(path: String): String {
return UriUtils.encodePath(path, "UTF-8")
}

@GetMapping("/file/**")
fun fileIndex(request: HttpServletRequest): ModelAndView {
val entity = repoService.getEntity(request.servletPath.removePrefix("/file/")) ?: throw NotFoundException()

if (entity is RepositoryDirectory) {
if (!request.servletPath.endsWith("/")) {
val redirectUrl = URI(request.servletPath + "/").toASCIIString()
return ModelAndView(RedirectView(redirectUrl))
return ModelAndView(RedirectView(urlEncodePath(request.servletPath + "/")))
}

val sortedChildren = entity.getChildren()
Expand All @@ -72,8 +75,7 @@ class FilesystemController(
))
}
}
val redirectUrl = URI("/download/${entity.relativePath}").toASCIIString()
return ModelAndView(RedirectView(redirectUrl))
return ModelAndView(RedirectView(urlEncodePath("/download/${entity.relativePath}")))
}

@GetMapping("/download/**")
Expand Down

0 comments on commit 3549e27

Please sign in to comment.