Skip to content

Commit 611354b

Browse files
authored
fix(answers): use UTF8 encoded index name (#269)
1 parent e444137 commit 611354b

File tree

5 files changed

+12
-17
lines changed

5 files changed

+12
-17
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Unreleased
22

3+
### Fixed
4+
- Answers: use UTF8 encoded index name (#269)
5+
36
### Changed
47
- `ClientRecommendation` renamed to `ClientPersonalization` (#267)
58
- Update Kotlin to 1.5.20

client/src/commonMain/kotlin/com/algolia/search/endpoint/internal/EndpointAnswers.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ internal class EndpointAnswersImpl(
2424
return transport.request(
2525
httpMethod = HttpMethod.Post,
2626
callType = CallType.Read,
27-
path = "1/answers/${indexName.raw}/prediction",
27+
path = "1/answers/${indexName.encode()}/prediction",
2828
requestOptions = requestOptions,
2929
body = body
3030
)
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
11
package com.algolia.search.helper.internal
22

3-
internal class StringUTF8 private constructor(val string: String) {
4-
5-
public companion object {
6-
7-
fun encode(string: String) = StringUTF8(string.encodeUTF8())
8-
}
9-
}
10-
113
internal expect fun String.encodeUTF8(): String

client/src/commonMain/kotlin/com/algolia/search/model/IndexName.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package com.algolia.search.model
22

33
import com.algolia.search.client.Index
44
import com.algolia.search.exception.EmptyStringException
5-
import com.algolia.search.helper.internal.StringUTF8
5+
import com.algolia.search.helper.internal.encodeUTF8
66
import com.algolia.search.helper.toIndexName
77
import com.algolia.search.model.internal.Raw
88
import com.algolia.search.serialize.RouteIndexesV1
@@ -25,12 +25,12 @@ public data class IndexName(
2525
if (raw.isBlank()) throw EmptyStringException("IndexName")
2626
}
2727

28-
private fun encode(): StringUTF8 {
29-
return StringUTF8.encode(raw)
28+
internal fun encode(): String {
29+
return raw.encodeUTF8()
3030
}
3131

3232
internal fun toPath(suffix: String? = null): String {
33-
return "$RouteIndexesV1/${encode().string}" + (suffix ?: "")
33+
return "$RouteIndexesV1/${encode()}" + (suffix ?: "")
3434
}
3535

3636
override fun toString(): String {

client/src/commonMain/kotlin/com/algolia/search/model/dictionary/Dictionary.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.algolia.search.model.dictionary
22

3-
import com.algolia.search.helper.internal.StringUTF8
3+
import com.algolia.search.helper.internal.encodeUTF8
44
import com.algolia.search.model.dictionary.DictionaryEntry.Compound
55
import com.algolia.search.model.dictionary.DictionaryEntry.Plural
66
import com.algolia.search.model.dictionary.DictionaryEntry.Stopword
@@ -28,12 +28,12 @@ public sealed class Dictionary<T : DictionaryEntry>(
2828
@Serializable
2929
public object Compounds : Dictionary<Compound>(KeyCompounds)
3030

31-
private fun encode(): StringUTF8 {
32-
return StringUTF8.encode(raw)
31+
private fun encode(): String {
32+
return raw.encodeUTF8()
3333
}
3434

3535
internal fun toPath(suffix: String? = null): String {
36-
return "$RouteDictionaries/${encode().string}" + (suffix ?: "")
36+
return "$RouteDictionaries/${encode()}" + (suffix ?: "")
3737
}
3838

3939
override fun toString(): String {

0 commit comments

Comments
 (0)