Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

URLDecoder #1441

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class EpubExtractor(

fun isEpub(path: Path): Boolean =
try {
getEntryStream(path, "mimetype").decodeToString() == "application/epub+zip"
getEntryStream(path, "mimetype").decodeToString().startsWith("application/epub+zip")
} catch (e: Exception) {
false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ import org.springframework.web.server.ResponseStatusException
import org.springframework.web.servlet.mvc.method.annotation.StreamingResponseBody
import java.io.FileNotFoundException
import java.io.OutputStream
import java.net.URLDecoder
import java.nio.charset.StandardCharsets.UTF_8
import java.nio.file.NoSuchFileException
import java.time.LocalDate
Expand Down Expand Up @@ -725,7 +726,7 @@ class BookController(
if (media.profile != MediaProfile.EPUB) throw ResponseStatusException(HttpStatus.BAD_REQUEST, "Book media type '${media.mediaType}' not compatible with requested profile")
if (!isFont) principal!!.user.checkContentRestriction(book)

val res = media.files.firstOrNull { it.fileName == resourceName } ?: throw ResponseStatusException(HttpStatus.NOT_FOUND)
val res = media.files.firstOrNull { listOf(it.fileName, URLDecoder.decode(it.fileName, "UTF-8")).contains(resourceName) } ?: throw ResponseStatusException(HttpStatus.NOT_FOUND)
val bytes =
try {
bookAnalyzer.getFileContent(BookWithMedia(book, media), resourceName)
Expand Down