mirror of
https://gitlab.com/ultrasonic/ultrasonic.git
synced 2025-04-24 12:50:58 +03:00
Support json with UTF-8 bom in VersionInterceptor.
Previously it was peeking at response body and put it into intermediate string that later used in json parsing. This preserves bom character and leads to parse fail. Now it passes peek body input stream to json parser that handles bom internally. Signed-off-by: Yahor Berdnikau <egorr.berd@gmail.com>
This commit is contained in:
parent
6f4c8baeb5
commit
1c7e5bb0f2
subsonic-api/src
integrationTest
kotlin/org/moire/ultrasonic/api/subsonic/interceptors
resources
main/kotlin/org/moire/ultrasonic/api/subsonic/interceptors
@ -44,6 +44,16 @@ class VersionInterceptorTest : BaseInterceptorTest() {
|
||||
.protocolVersion `should equal` SubsonicAPIVersions.V1_13_0
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should update version from response with utf-8 bom`() {
|
||||
mockWebServerRule.enqueueResponse("ping_ok_utf8_bom.json")
|
||||
|
||||
client.newCall(createRequest {}).execute()
|
||||
|
||||
(interceptor as VersionInterceptor)
|
||||
.protocolVersion `should equal` SubsonicAPIVersions.V1_16_0
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `Should not update version if response json doesn't contain version`() {
|
||||
mockWebServerRule.enqueueResponse("non_subsonic_response.json")
|
||||
|
@ -0,0 +1,4 @@
|
||||
{"subsonic-response":{
|
||||
"status": "ok",
|
||||
"version": "1.16.0"
|
||||
}}
|
@ -48,8 +48,7 @@ internal class VersionInterceptor(
|
||||
}
|
||||
|
||||
private fun tryUpdateProtocolVersion(response: Response) {
|
||||
val content = response.peekBody(DEFAULT_PEEK_BYTE_COUNT)
|
||||
.byteStream().bufferedReader().readText()
|
||||
val content = response.peekBody(DEFAULT_PEEK_BYTE_COUNT).byteStream()
|
||||
|
||||
try {
|
||||
val jsonReader = jsonFactory.createParser(content)
|
||||
|
Loading…
x
Reference in New Issue
Block a user