Skip to content

Commit

Permalink
kotlin: Sort lists/sets before comma separating and url encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-mman committed Feb 12, 2025
1 parent 8426e91 commit d04ef57
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions kotlin/lib/src/main/kotlin/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,15 @@ internal fun serializeQueryParam(v: Any): String {
return if (isEnum(v)) {
(v as ToQueryParam).toQueryParam()
} else if (isList(v)) {
(v as List<*>).joinToString(",")
// sort before comma separating the values (helps me assert when testing)
(v as List<Any>).map { serializeQueryParam(it) }.sorted().joinToString(",")
} else if (isSet(v)) {
(v as Set<*>).joinToString(",")
(v as Set<Any>)
.asSequence()
.map { serializeQueryParam(it) }
.toList()
.sorted()
.joinToString(",")
} else {
v.toString()
}
Expand Down

0 comments on commit d04ef57

Please sign in to comment.