Skip to content

Commit ddf44ae

Browse files
authored
Merge pull request #196 from algolia/fix/client
fix(client): omit all line terminators in the base64 encoder
2 parents 8642701 + 2ec6c55 commit ddf44ae

File tree

6 files changed

+36
-4
lines changed

6 files changed

+36
-4
lines changed

build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ repositories {
3232
mavenCentral()
3333
maven { url = URI("https://dl.bintray.com/kotlin/ktor") }
3434
maven { url = URI("https://kotlin.bintray.com/kotlinx") }
35+
maven { url = URI("https://oss.sonatype.org/content/repositories/snapshots") }
3536
}
3637

3738
version = Library.version

buildSrc/src/main/kotlin/Robolectric.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ object Robolectric : Dependency {
22

33
override val group = "org.robolectric"
44
override val artifact = "robolectric"
5-
override val version = "4.3.1"
5+
override val version = "4.4-SNAPSHOT" // TODO: Remove the `SNAPSHOT` and the gradle repository when the final version is out.
66
}

src/androidMain/kotlin/com/algolia/search/helper/Hashing.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ internal actual fun String.sha256(key: String): String {
1616
}
1717

1818
internal actual fun String.encodeBase64(): String {
19-
return Base64.encodeToString(toByteArray(), Base64.DEFAULT)
19+
return Base64.encodeToString(toByteArray(), Base64.NO_WRAP)
2020
}
2121

2222
internal actual fun String.decodeBase64(): String {
23-
return String(Base64.decode(this, Base64.DEFAULT))
23+
return String(Base64.decode(this, Base64.NO_WRAP))
2424
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package helper
2+
3+
import android.os.Build
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
import org.junit.runner.RunWith
6+
import org.robolectric.annotation.Config
7+
8+
@RunWith(AndroidJUnit4::class)
9+
@Config(sdk = [Build.VERSION_CODES.P])
10+
internal class TestHashingAndroid : TestHashing()
Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,31 @@
11
package helper
22

3+
import com.algolia.search.helper.decodeBase64
4+
import com.algolia.search.helper.encodeBase64
35
import com.algolia.search.helper.sha256
46
import shouldEqual
57
import kotlin.test.Test
68

7-
internal class TestHashing {
9+
internal abstract class TestHashing {
810

911
@Test
1012
fun sha256() {
1113
"1234".sha256("test") shouldEqual "24c4f0295e1bea74f9a5cb5bc40525c8889d11c78c4255808be00defe666671f"
1214
}
15+
16+
@Test
17+
fun encoding() {
18+
val url = "AZ:/19&@';#"
19+
val hash = "QVo6LzE5JkAnOyM="
20+
21+
url.encodeBase64() shouldEqual hash
22+
}
23+
24+
@Test
25+
fun decoding() {
26+
val url = "AZ:/19&@';#"
27+
val hash = "QVo6LzE5JkAnOyM="
28+
29+
hash.decodeBase64() shouldEqual url
30+
}
1331
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package helper
2+
3+
internal class TestHashingJVM : TestHashing()

0 commit comments

Comments
 (0)