Skip to content

Commit d1252c9

Browse files
Fix csv param bugs
1 parent a3d6206 commit d1252c9

File tree

3 files changed

+6
-4
lines changed

3 files changed

+6
-4
lines changed

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
invirtVersion = 1.2.0
1+
invirtVersion = 1.2.1
22

33
kafkaVersion = 3.8.0
44
kotlinVersion = 2.0.0

invirt-core/src/main/kotlin/invirt/core/uri.kt

+2-2
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ fun Uri.csvAppend(name: String, value: Any): Uri = replaceQuery(
6363
)
6464

6565
fun Uri.csvRemove(name: String, value: Any): Uri {
66-
val values = csvQuery(name).minus(value).toSet()
66+
val values = csvQuery(name).toMutableSet().filter { it != value.toString() }
6767
return if (values.isEmpty()) {
6868
removeQuery(name)
6969
} else {
@@ -73,7 +73,7 @@ fun Uri.csvRemove(name: String, value: Any): Uri {
7373

7474
fun Uri.csvToggle(name: String, value: Any): Uri {
7575
val values = csvQuery(name)
76-
return if (values.contains(value)) {
76+
return if (values.contains(value.toString())) {
7777
csvRemove(name, value)
7878
} else {
7979
csvAppend(name, value)

invirt-core/src/test/kotlin/invirt/core/UriTest.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,15 @@ class UriTest : StringSpec({
8888
Uri.of("/test?q=John").csvRemove("q", "John").toString() shouldBe "/test"
8989
Uri.of("/test?q=John%2CJane").csvRemove("q", "Jane").toString() shouldBe "/test?q=John"
9090
Uri.of("/test?q=John,Jane").csvRemove("q", "John").toString() shouldBe "/test?q=Jane"
91+
Uri.of("/test?q=3,5").csvRemove("q", 3).toString() shouldBe "/test?q=5"
9192
}
9293

9394
"csvToggle" {
9495
Uri.of("/test").csvToggle("q", "John").toString() shouldBe "/test?q=John"
9596
Uri.of("/test?q=John").csvToggle("q", "John").toString() shouldBe "/test"
9697
Uri.of("/test?q=John").csvToggle("q", "Jane").toString() shouldBe "/test?q=John%2CJane"
9798
Uri.of("/test?q=John%2CJane").csvToggle("q", "Jane").toString() shouldBe "/test?q=John"
98-
Uri.of("/test?q=John%2CJane").csvToggle("q", "John").toString() shouldBe "/test?q=Jane"
99+
Uri.of("/test?q=John,Jane").csvToggle("q", "John").toString() shouldBe "/test?q=Jane"
100+
Uri.of("/test?q=1,2").csvToggle("q", 2).toString() shouldBe "/test?q=1"
99101
}
100102
})

0 commit comments

Comments
 (0)