Importing json should tolerate a BOM
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
package org.jeudego.pairgoth.web
|
package org.jeudego.pairgoth.web
|
||||||
|
|
||||||
import com.republicate.kson.Json
|
import com.republicate.kson.Json
|
||||||
|
import org.apache.commons.io.input.BOMInputStream
|
||||||
import org.jeudego.pairgoth.util.Upload
|
import org.jeudego.pairgoth.util.Upload
|
||||||
import org.jeudego.pairgoth.view.ApiTool
|
import org.jeudego.pairgoth.view.ApiTool
|
||||||
import org.jeudego.pairgoth.view.PairgothTool.Companion.EXAMPLES_DIRECTORY
|
import org.jeudego.pairgoth.view.PairgothTool.Companion.EXAMPLES_DIRECTORY
|
||||||
|
import java.io.ByteArrayInputStream
|
||||||
|
import java.io.InputStreamReader
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import javax.servlet.http.HttpServlet
|
import javax.servlet.http.HttpServlet
|
||||||
import javax.servlet.http.HttpServletRequest
|
import javax.servlet.http.HttpServletRequest
|
||||||
@@ -23,7 +26,8 @@ class ImportServlet: HttpServlet() {
|
|||||||
val bytes = uploads.first().second
|
val bytes = uploads.first().second
|
||||||
var apiResp: Json? = null
|
var apiResp: Json? = null
|
||||||
if (name.endsWith(".tour")) {
|
if (name.endsWith(".tour")) {
|
||||||
val json = Json.parse(bytes.toString(StandardCharsets.UTF_8))
|
val content = InputStreamReader(BOMInputStream(ByteArrayInputStream(bytes)), StandardCharsets.UTF_8).readText()
|
||||||
|
val json = Json.parse(content)
|
||||||
if (json == null || !json.isObject) {
|
if (json == null || !json.isObject) {
|
||||||
resp.sendError(HttpServletResponse.SC_BAD_REQUEST)
|
resp.sendError(HttpServletResponse.SC_BAD_REQUEST)
|
||||||
} else {
|
} else {
|
||||||
|
Reference in New Issue
Block a user