Skip to content

Commit a8faae9

Browse files
committed
Fix JSON escaping
1 parent 1019203 commit a8faae9

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

android/app/build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ dependencies {
5252
implementation 'com.beust:klaxon:5.5'
5353
implementation 'androidx.work:work-runtime-ktx:2.7.1'
5454
implementation 'androidx.appcompat:appcompat:1.4.2'
55+
implementation 'org.apache.commons:commons-text:1.9'
5556
implementation 'com.google.android.material:material:1.6.1'
5657
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
5758
testImplementation 'junit:junit:4.13.2'

android/app/src/main/java/com/httpsms/HttpSmsApiService.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import okhttp3.MediaType.Companion.toMediaType
44
import okhttp3.OkHttpClient
55
import okhttp3.Request
66
import okhttp3.RequestBody.Companion.toRequestBody
7+
import org.apache.commons.text.StringEscapeUtils
78
import timber.log.Timber
89
import java.net.URI
910
import java.time.ZonedDateTime
@@ -63,9 +64,10 @@ class HttpSmsApiService(private val apiKey: String) {
6364
val formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'000000'ZZZZZ")
6465
val timestampString = formatter.format(timestamp).replace("+", "Z")
6566

67+
6668
val body = """
6769
{
68-
"content": "$content",
70+
"content": "${StringEscapeUtils.escapeJson(content)}",
6971
"from": "$from",
7072
"timestamp": "$timestampString",
7173
"to": "$to"
@@ -80,7 +82,7 @@ class HttpSmsApiService(private val apiKey: String) {
8082

8183
val response = client.newCall(request).execute()
8284
if (!response.isSuccessful) {
83-
Timber.e("error response [${response.body?.string()}] with code [${response.code}] while receiving message [${body}]}]")
85+
Timber.e("error response [${response.body?.string()}] with code [${response.code}] while receiving message [${body}]")
8486
return
8587
}
8688

0 commit comments

Comments
 (0)